ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-09-03 02:14:11
Exec Total Coverage
Lines: 3103 8696 35.7%
Functions: 84 304 27.6%
Branches: 2690 7667 35.1%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "base/md5.h"
33 #include "hero_tiles.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include "iter.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern uint8_t ViewLayer3BG, ViewLayer2BG;
59 extern int32_t LayerDitherBG, LayerDitherSz;
60 extern bool NoHighlightLayer0;
61
62 using std::string;
63 using std::pair;
64
65 #define COLOR_SOLID vc(4)
66 #define COLOR_SLOPE vc(13)
67 #define COLOR_LADDER vc(6)
68 //#define COLOR_EFFECT vc(10)
69
70 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
71 extern char msgbuf[MSG_NEW_SIZE*8];
72
73 extern string zScript;
74
75 12 zmap Map;
76 int32_t prv_mode=0;
77
78 bool save_warn=true;
79
80 int32_t COMBOPOS(int32_t x, int32_t y)
81 {
82 return (((y) & 0xF0) + ((x) >> 4));
83 }
84 int32_t COMBOPOS_B(int32_t x, int32_t y)
85 {
86 if(unsigned(x) >= 256 || unsigned(y) >= 176)
87 return -1;
88 return COMBOPOS(x,y);
89 }
90 int32_t COMBOX(int32_t pos)
91 {
92 return ((pos) % 16 * 16);
93 }
94 int32_t COMBOY(int32_t pos)
95 {
96 return ((pos) & 0xF0);
97 }
98
99 void reset_dmap(int32_t index)
100 {
101 bound(index,0,MAXDMAPS-1);
102 DMaps[index].clear();
103 DMaps[index].title = "";
104 sprintf(DMaps[index].intro, " ");
105 }
106
107 void reset_dmaps()
108 {
109 for(int32_t i=0; i<MAXDMAPS; i++)
110 reset_dmap(i);
111 }
112
113 void truncate_dmap_title(std::string& title)
114 {
115 title.resize(21, ' ');
116 }
117
118 mapscr* zmap::get_prvscr()
119 {
120 return &prvscr;
121 }
122
123
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 23 times.
138 zmap::zmap()
124 {
125 23 can_paste=false;
126 23 prv_cmbcycle=0;
127 23 prv_advance=0;
128 23 prv_freeze=0;
129 23 copyffc=-1;
130
131 23 memset(scrpos, 0, sizeof(scrpos));
132 23 memset(scrview, 0, sizeof(scrview));
133 23 screens=NULL;
134 23 prv_time=0;
135 23 prv_scr=0;
136 23 prv_map=0;
137 23 copyscr=0;
138 23 cursor={};
139 copymap=0;
140 layer_target_map = 0;
141 layer_target_scr = 0;
142 layer_target_multiple = 0;
143 }
144
145 11 void zmap::clear()
146 {
147
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
148 11 }
149 void zmap::force_refr_pointer()
150 {
151 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
152 screens = nullptr;
153 else screens = &TheMaps[cursor.map*MAPSCRS];
154 }
155 bool zmap::CanUndo()
156 {
157 return undo_stack.size() > 0;
158 }
159 bool zmap::CanRedo()
160 {
161 return redo_stack.size() > 0;
162 }
163 bool zmap::CanPaste()
164 {
165 return can_paste;
166 }
167 int32_t zmap::CopyScr()
168 {
169 return (copymap<<8)+copyscr;
170 }
171 int32_t zmap::getCopyFFC()
172 {
173 return copyffc;
174 }
175 set_ffc_command::data_t zmap::getCopyFFCData()
176 {
177 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
178 }
179 67 int32_t zmap::getMapCount()
180 {
181 67 return map_count;
182 }
183 int32_t zmap::getLayerTargetMap()
184 {
185 return layer_target_map;
186 }
187 int32_t zmap::getLayerTargetScr()
188 {
189 return layer_target_scr;
190 }
191 int32_t zmap::getLayerTargetMultiple()
192 {
193 return layer_target_multiple;
194 }
195 bool zmap::isDungeon(int32_t scr)
196 {
197 for(int32_t i=0; i<4; i++)
198 {
199 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
200 {
201 return false;
202 }
203 }
204
205 return true;
206 }
207
208 bool zmap::clearall(bool validate)
209 {
210 Color=0;
211 char tbuf[10];
212
213 if((header.templatepath[0]!=0)&&validate)
214 {
215 if(!valid_zqt(header.templatepath))
216 {
217 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
218 return false;
219 }
220 }
221
222 for(int32_t i=0; i<map_count; i++)
223 {
224 setCurrMap(i);
225 sprintf(tbuf, "%d", i);
226 clearmap(true);
227 }
228
229 setCurrMap(0);
230 return true;
231 }
232
233 bool zmap::reset_templates(bool validate)
234 {
235 //why are we doing this?
236 if(colordata==NULL)
237 {
238 return false;
239 }
240
241 //int32_t ret;
242 word version, build, dummy, sversion=0;
243 byte dummyc;
244 word dummyw;
245 //int32_t section_size;
246 word temp_map_count;
247 mapscr temp_mapscr;
248 PACKFILE *f=NULL;
249
250 // setPackfilePassword(datapwd);
251 f=open_quest_template(&header, "modules/classic/default.qst", validate);
252 get_version_and_build(f, &version, &build);
253
254 if(!find_section(f, ID_MAPS))
255 {
256 // setPackfilePassword(NULL);
257 return false;
258 }
259
260 //section version info
261 if(!p_igetw(&sversion,f))
262 {
263 return false;
264 }
265
266 if(!p_igetw(&dummy,f))
267 {
268 return false;
269 }
270
271 //section size
272 dword dummy_size;
273 if(!p_igetl(&dummy_size,f))
274 {
275 return false;
276 }
277
278 //finally... section data
279 if(!p_igetw(&temp_map_count,f))
280 {
281 return false;
282 }
283
284 if(version>12)
285 {
286 if(!p_getc(&dummyc,f))
287 return qe_invalid;
288
289 if(!p_getc(&dummyc,f))
290 return qe_invalid;
291
292 if(!p_igetw(&dummyw,f))
293 return qe_invalid;
294
295 if(!p_igetw(&dummyw,f))
296 return qe_invalid;
297
298 if(!p_igetw(&dummyw,f))
299 return qe_invalid;
300
301 if(!p_igetw(&dummyw,f))
302 return qe_invalid;
303
304 if(!p_igetw(&dummyw,f))
305 return qe_invalid;
306
307 if(!p_igetw(&dummyw,f))
308 return qe_invalid;
309
310 if(!p_igetw(&dummyw,f))
311 return qe_invalid;
312
313 if(!p_igetw(&dummyw,f))
314 return qe_invalid;
315
316 if(!p_igetw(&dummyw,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_getc(&dummyc,f))
323 return qe_invalid;
324
325 if(!p_getc(&dummyc,f))
326 return qe_invalid;
327 }
328
329 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
330 {
331 readmapscreen(f, &header, &temp_mapscr, sversion);
332 }
333
334 readmapscreen(f, &header, &TheMaps[128], sversion);
335 readmapscreen(f, &header, &TheMaps[129], sversion);
336
337 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
338 {
339 readmapscreen(f, &header, &temp_mapscr, sversion);
340 }
341
342 if(version>12)
343 {
344 if(!p_getc(&dummyc,f))
345 return qe_invalid;
346
347 if(!p_getc(&dummyc,f))
348 return qe_invalid;
349
350 if(!p_igetw(&dummyw,f))
351 return qe_invalid;
352
353 if(!p_igetw(&dummyw,f))
354 return qe_invalid;
355
356 if(!p_igetw(&dummyw,f))
357 return qe_invalid;
358
359 if(!p_igetw(&dummyw,f))
360 return qe_invalid;
361
362 if(!p_igetw(&dummyw,f))
363 return qe_invalid;
364
365 if(!p_igetw(&dummyw,f))
366 return qe_invalid;
367
368 if(!p_igetw(&dummyw,f))
369 return qe_invalid;
370
371 if(!p_igetw(&dummyw,f))
372 return qe_invalid;
373
374 if(!p_igetw(&dummyw,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_getc(&dummyc,f))
381 return qe_invalid;
382
383 if(!p_getc(&dummyc,f))
384 return qe_invalid;
385 }
386
387 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
388 {
389 readmapscreen(f, &header, &temp_mapscr, sversion);
390 }
391
392 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
393 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
394
395 pack_fclose(f);
396 clear_quest_tmpfile();
397
398 return true;
399 }
400
401 bool zmap::clearmap(bool newquest)
402 {
403 if(cursor.map<map_count)
404 {
405 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
406 {
407 clearscr(i);
408 }
409
410 setCurrScr(0);
411
412 if(newquest)
413 {
414 if(!reset_templates(false))
415 {
416 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
417 }
418 }
419 }
420
421 return true;
422 }
423
424 MapCursor zmap::getCursor() const
425 {
426 return cursor;
427 }
428
429 void zmap::setCursor(MapCursor new_cursor)
430 {
431 if (cursor == new_cursor)
432 return;
433
434 if (!screens) Color = -1;
435
436 cursor = new_cursor;
437
438 refresh_color();
439
440 reset_combo_animations2();
441 mmap_mark_dirty();
442 regions_mark_dirty();
443 refresh(rALL);
444 }
445
446 bool zmap::isValidPosition(ComboPosition pos) const
447 {
448 return pos.is_valid(cursor);
449 }
450
451 int zmap::getScreenForPosition(ComboPosition pos) const
452 {
453 return cursor.viewscr + pos.screen_offset();
454 }
455
456 mapscr* zmap::CurrScr()
457 {
458 return screens+cursor.screen;
459 }
460 mapscr* zmap::Scr(int32_t scr)
461 {
462 return screens+scr;
463 }
464 mapscr* zmap::Scr(ComboPosition pos)
465 {
466 if (!pos.is_valid(cursor))
467 return nullptr;
468
469 int screen_offset = pos.screen_offset();
470 int screen = cursor.viewscr + screen_offset;
471 return AbsoluteScr(cursor.map, screen);
472 }
473 mapscr* zmap::Scr(ComboPosition pos, int layer)
474 {
475 int map = cursor.map;
476 int screen = cursor.viewscr + pos.screen_offset();
477 if (layer)
478 {
479 mapscr* scr = Map.AbsoluteScr(map, screen);
480 map = scr->layermap[CurrentLayer-1]-1;
481 screen = scr->layerscreen[CurrentLayer-1];
482 }
483
484 return AbsoluteScr(map, screen);
485 }
486 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
487 {
488 mapscr* scr = Scr(pos, layer);
489 if (scr && !(scr->valid&mVALID))
490 {
491 scr->valid |= mVALID;
492 setcolor(Color, scr);
493 }
494 return scr;
495 }
496 mapscr* zmap::AbsoluteScr(int32_t scr)
497 {
498 if(unsigned(scr) >= MAPSCRS*getMapCount())
499 return nullptr;
500 return &TheMaps[scr];
501 }
502 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
503 {
504 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
505 return nullptr;
506 return AbsoluteScr((map*MAPSCRS)+scr);
507 }
508 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
509 {
510 mapscr* scr = AbsoluteScr(map, screen);
511 if (scr && !(scr->valid&mVALID))
512 {
513 scr->valid |= mVALID;
514 setcolor(Color, scr);
515 }
516 return scr;
517 }
518 void zmap::set_prvscr(int32_t map, int32_t scr)
519 {
520 prvscr = *get_canonical_scr(map, scr);
521
522 for(int32_t i=0; i<6; i++)
523 {
524 if(prvscr.layermap[i]>0)
525 {
526 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
527 }
528 else
529 prvlayers[i].valid = 0;
530 }
531
532 prv_map=map;
533 prv_scr=scr;
534 }
535 92 int32_t zmap::getCurrMap()
536 {
537 92 return cursor.map;
538 }
539 22 void zmap::regions_mark_dirty()
540 {
541 22 regions_dirty = true;
542 22 }
543 void zmap::regions_refresh()
544 {
545 if (!regions_dirty)
546 return;
547
548 regions_dirty = false;
549 region_descriptions.clear();
550
551 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
552 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
553 region_descriptions.clear();
554 }
555 const std::vector<region_description>& zmap::get_region_descriptions()
556 {
557 regions_refresh();
558 return region_descriptions;
559 }
560 bool zmap::is_region(int screen)
561 {
562 if (screen < 0 || screen >= 128)
563 return false;
564
565 regions_refresh();
566 return current_map_region_ids[screen];
567 }
568 bool zmap::isDark(int scr)
569 {
570 return (screens[scr].flags&fDARK)!=0;
571 }
572 bool zmap::isValid(int32_t scr)
573 {
574 return (screens[scr].valid&mVALID)!=0;
575 }
576 bool zmap::isValid(int32_t map, int32_t scr)
577 {
578 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
579 }
580
581 11 void zmap::setCurrMap(int32_t index)
582 {
583
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
584 11 scrpos[cursor.map] = cursor.screen;
585 11 scrview[cursor.map] = cursor.viewscr;
586 11 cursor.map = bound(index,0,map_count);
587 11 screens = &TheMaps[cursor.map*MAPSCRS];
588
589 11 cursor.viewscr = scrview[cursor.map];
590 11 cursor.setScreen(scrpos[cursor.map]);
591
592 11 refresh_color();
593
594 11 reset_combo_animations2();
595 11 mmap_mark_dirty();
596 11 regions_mark_dirty();
597 11 }
598
599 20 int32_t zmap::getCurrScr()
600 {
601 20 return cursor.screen;
602 }
603 11 void zmap::setCurrScr(int32_t scr)
604 {
605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (scr == cursor.screen)
606 return;
607
608 11 cursor.setScreen(scr);
609
610 11 refresh_color();
611
612 11 reset_combo_animations2();
613 11 setlayertarget();
614 11 mmap_mark_dirty();
615 11 regions_mark_dirty();
616 11 }
617
618 int32_t zmap::getViewScr()
619 {
620 return cursor.viewscr;
621 }
622
623 11 void zmap::setViewSize(int32_t size)
624 {
625 11 cursor.setSize(size);
626 11 }
627
628 8 int32_t zmap::getViewSize()
629 {
630 8 return cursor.size;
631 }
632
633 11 void zmap::setlayertarget()
634 {
635 11 layer_target_map = 0;
636 11 layer_target_multiple = 0;
637
638
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
639 {
640
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
641 {
642 7616 int32_t i=(m*MAPSCRS+s);
643 7616 mapscr *ts=&TheMaps[i];
644
645 // Search through each layer
646
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
647 {
648
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 45679 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
649 {
650 if(layer_target_map > 0)
651 {
652 layer_target_multiple += 1;
653 continue;
654 }
655
656 layer_target_map = m+1;
657 layer_target_scr = s;
658 }
659 45696 }
660 7616 }
661 56 }
662 11 }
663
664 22 void zmap::refresh_color()
665 {
666 22 auto color = getcolor();
667
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 21 times.
22 if (Color != color)
668 {
669 21 loadlvlpal(color);
670 21 rebuild_trans_table();
671 21 }
672 22 }
673
674 void zmap::setcolor(int color, mapscr* scr)
675 {
676 if (!scr)
677 scr = CurrScr();
678 scr->valid |= mVALID;
679 scr->color = color;
680
681 refresh_color();
682
683 mmap_mark_dirty();
684 }
685
686 22 int32_t zmap::getcolor()
687 {
688
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 mapscr& scr = prv_mode ? prvscr : screens[cursor.screen];
689
690
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 4 times.
22 if (scr.valid & mVALID)
691 18 return scr.color;
692
693 4 return map_infos[cursor.map].autopalette;
694 22 }
695
696 void zmap::resetflags()
697 {
698 byte *di=&(screens[cursor.screen].valid);
699
700 for(int32_t i=1; i<48; i++)
701 {
702 *(di+i)=0;
703 }
704 }
705
706 word zmap::tcmbdat(int32_t pos)
707 {
708 return screens[TEMPLATE].data[pos];
709 }
710
711 word zmap::tcmbcset(int32_t pos)
712 {
713 return screens[TEMPLATE].cset[pos];
714 }
715
716 int32_t zmap::tcmbflag(int32_t pos)
717 {
718 return screens[TEMPLATE].sflag[pos];
719 }
720
721 word zmap::tcmbdat2(int32_t pos)
722 {
723 return screens[TEMPLATE2].data[pos];
724 }
725
726 word zmap::tcmbcset2(int32_t pos)
727 {
728 return screens[TEMPLATE2].cset[pos];
729 }
730
731 int32_t zmap::tcmbflag2(int32_t pos)
732 {
733 return screens[TEMPLATE2].sflag[pos];
734 }
735
736 void zmap::TemplateAll()
737 {
738 StartListCommand();
739 for(int32_t i=0; i<128; i++)
740 {
741 if((screens[i].valid&mVALID) && isDungeon(i))
742 DoTemplateCommand(-1, -1, i);
743 }
744 FinishListCommand();
745 }
746
747 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
748 {
749 if(scr==TEMPLATE)
750 return;
751
752 if(!(screens[scr].valid&mVALID))
753 screens[scr].color=Color;
754
755 screens[scr].valid|=mVALID;
756
757 for(int32_t i=0; i<32; i++)
758 {
759 screens[scr].data[i]=screens[TEMPLATE].data[i];
760 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
761 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
762 }
763
764 for(int32_t i=144; i<176; i++)
765 {
766 screens[scr].data[i]=screens[TEMPLATE].data[i];
767 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
768 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
769 }
770
771 for(int32_t y=2; y<=9; y++)
772 {
773 int32_t j=y<<4;
774 screens[scr].data[j]=screens[TEMPLATE].data[j];
775 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
776 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
777 ++j;
778 screens[scr].data[j]=screens[TEMPLATE].data[j];
779 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
780 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
781 ++j;
782 j+=12;
783 screens[scr].data[j]=screens[TEMPLATE].data[j];
784 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
785 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
786 ++j;
787 screens[scr].data[j]=screens[TEMPLATE].data[j];
788 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
789
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 }
793
794 if(floorcombo!=-1)
795 {
796 for(int32_t y=2; y<9; y++)
797 for(int32_t x=2; x<14; x++)
798 {
799 int32_t i=(y<<4)+x;
800 screens[scr].data[i] = floorcombo;
801 screens[scr].cset[i] = floorcset;
802 }
803 }
804
805 for(int32_t i=0; i<4; i++)
806 putdoor(scr,i,screens[scr].door[i]);
807 }
808
809
810 void zmap::clearscr(int32_t scr)
811 {
812 screens[scr].zero_memory();
813 screens[scr].valid=mVERSION;
814 auto const& mapinf = map_infos[cursor.map];
815 for(int q = 0; q < 6; ++q)
816 {
817 auto layer = mapinf.autolayers[q];
818 screens[scr].layermap[q] = layer;
819 screens[scr].layerscreen[q] = layer ? scr : 0;
820 }
821 screens[scr].color = mapinf.autopalette;
822 if (scr == cursor.screen)
823 refresh_color();
824 mmap_mark_dirty();
825 }
826
827 const char *loaderror[] =
828 {
829
830 "OK","File not found","Incomplete data",
831 "Invalid version","Invalid file"
832
833 };
834
835 int32_t zmap::load(const char *path)
836 {
837 PACKFILE *f=pack_fopen_password(path,F_READ, "");
838
839 if(!f)
840 return 1;
841
842
843 int16_t version;
844 byte build;
845
846 //get the version
847 if(!p_igetw(&version,f))
848 {
849 goto file_error;
850 }
851
852 //get the build
853 if(!p_getc(&build,f))
854 {
855 goto file_error;
856 }
857
858 for(int32_t i=0; i<MAPSCRS; i++)
859 {
860 mapscr tmpimportscr;
861 tmpimportscr.zero_memory();
862 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
863 {
864 al_trace("failed zmap::load\n");
865 goto file_error;
866 }
867
868 switch(ImportMapBias)
869 {
870 case 0:
871 *(screens+i) = tmpimportscr;
872 break;
873
874 case 1:
875 if(!(screens[i].valid&mVALID))
876 {
877 *(screens+i) = tmpimportscr;
878 }
879 break;
880
881 case 2:
882 if(tmpimportscr.valid&mVALID)
883 {
884 *(screens+i) = tmpimportscr;
885 }
886 break;
887 }
888 }
889
890
891 pack_fclose(f);
892
893 setCurrScr(0);
894 mmap_mark_dirty();
895 regions_mark_dirty();
896 return 0;
897
898 file_error:
899 pack_fclose(f);
900 clearmap(false);
901 return 2;
902 }
903
904 int32_t zmap::save(const char *path)
905 {
906 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
907
908 if(!f)
909 return 1;
910
911 if(!p_iputw(V_MAPS,f))
912 {
913 pack_fclose(f);
914 return 3;
915 }
916
917 // This was the "build number", but that's totally useless here. Keep this junk byte
918 // so as not to totally break exports between ZC versions.
919 if(!p_putc(0,f))
920 {
921 pack_fclose(f);
922 return 3;
923 }
924
925 for(int32_t i=0; i<MAPSCRS; i++)
926 {
927 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
928 {
929 pack_fclose(f);
930 return 2;
931 }
932 }
933
934 pack_fclose(f);
935 return 0;
936 }
937
938
939 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
940 {
941 // Hookshots can be blocked by solid combos on all 3 ground layers.
942 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
943
944 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
945 return true;
946 if (c->walk&(1<<i))
947 return false;
948
949 for(int32_t k=0; k<2; k++)
950 {
951 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
952
953 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
954 {
955 return false;
956 }
957 }
958
959 return true;
960 }
961
962 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
963 {
964 // Hookshots can be blocked by solid combos on all 3 ground layers.
965 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
966
967 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
968 return true;
969 if (c->walk&(1<<i))
970 return false;
971
972 for(int32_t k=0; k<2; k++)
973 {
974 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
975
976 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
977 {
978 return false;
979 }
980 }
981
982 return true;
983 }
984
985 bool zmap::isstepable(int32_t combo)
986 {
987 // This is kind of odd but it's true to the engine (see maps.cpp)
988 return (combo_class_buf[combobuf[combo].type].ladder_pass);
989 }
990
991 // Returns the letter of the warp combo.
992 int32_t zmap::warpindex(int32_t combo)
993 {
994 switch(combobuf[combo].type)
995 {
996 case cCAVE:
997 case cPIT:
998 case cSTAIR:
999 case cCAVE2:
1000 case cSWIMWARP:
1001 case cDIVEWARP:
1002 case cSWARPA:
1003 return 0;
1004
1005 case cCAVEB:
1006 case cPITB:
1007 case cSTAIRB:
1008 case cCAVE2B:
1009 case cSWIMWARPB:
1010 case cDIVEWARPB:
1011 case cSWARPB:
1012 return 1;
1013
1014 case cCAVEC:
1015 case cPITC:
1016 case cSTAIRC:
1017 case cCAVE2C:
1018 case cSWIMWARPC:
1019 case cDIVEWARPC:
1020 case cSWARPC:
1021 return 2;
1022
1023 case cCAVED:
1024 case cPITD:
1025 case cSTAIRD:
1026 case cCAVE2D:
1027 case cSWIMWARPD:
1028 case cDIVEWARPD:
1029 case cSWARPD:
1030 return 3;
1031
1032 case cPITR:
1033 case cSTAIRR:
1034 case cSWARPR:
1035 return 4;
1036 }
1037
1038 return -1;
1039
1040 }
1041
1042 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1043 {
1044 if(top)
1045 line(dest,x,y,x+15,y,c);
1046 rectfill(dest,x,y,x+3,y+15,c);
1047 rectfill(dest,x+12,y,x+15,y+15,c);
1048 rectfill(dest,x+4,y+2,x+11,y+5,c);
1049 rectfill(dest,x+4,y+10,x+11,y+13,c);
1050 }
1051
1052 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1053 {
1054 line(dest,x,y,x+15,y,c);
1055 }
1056
1057 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1058 {
1059 int32_t cx = COMBOX(pos);
1060 int32_t cy = COMBOY(pos);
1061
1062 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1063
1064 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1065
1066 int32_t bridgedetected = 0;
1067
1068 for(int32_t i=0; i<4; i++)
1069 {
1070 int32_t tx=((i&2)<<2)+x;
1071 int32_t ty=((i&1)<<3)+y;
1072 int32_t tx2=((i&2)<<2)+cx;
1073 int32_t ty2=((i&1)<<3)+cy;
1074 for (int32_t m = layer; m <= 1; m++)
1075 {
1076 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1077 {
1078 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1079 {
1080 bridgedetected |= (1<<i);
1081 }
1082 }
1083 else
1084 {
1085 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1086 {
1087 bridgedetected |= (1<<i);
1088 }
1089 }
1090 }
1091 if (bridgedetected & (1<<i))
1092 {
1093 if (i >= 3) break;
1094 else continue;
1095 }
1096 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1097 {
1098 for(int32_t k=0; k<8; k+=2)
1099 for(int32_t j=0; j<8; j+=2)
1100 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1101 }
1102 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1103 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1104
1105 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1106 {
1107 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1108 {
1109 for(int32_t k=0; k<8; k+=2)
1110 for(int32_t j=0; j<8; j+=2)
1111 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1112 }
1113 else
1114 {
1115 int32_t color = COLOR_SOLID;
1116
1117 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1118 color=vc(6);
1119 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1120 color=vc(7);
1121
1122 rectfill(dest,tx,ty,tx+7,ty+7,color);
1123 }
1124 }
1125 }
1126
1127 bridgedetected = 0;
1128 for(int32_t i=0; i<4; i++)
1129 {
1130 int32_t tx2=((i&2)<<2)+cx;
1131 int32_t ty2=((i&1)<<3)+cy;
1132 for (int32_t m = 0; m <= 1; m++)
1133 {
1134 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1135 {
1136 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1137 {
1138 bridgedetected |= (1<<i);
1139 }
1140 }
1141 else
1142 {
1143 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1144 {
1145 bridgedetected |= (1<<i);
1146 }
1147 }
1148 }
1149 }
1150
1151 // Draw damage combos
1152 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1153 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1154 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1155 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1156 || combo_class_buf[c1.type].modify_hp_amount
1157 || combo_class_buf[c2.type].modify_hp_amount;
1158
1159 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1160
1161 if(dmg)
1162 {
1163 if (bridgedetected <= 0)
1164 {
1165 for(int32_t k=0; k<16; k+=2)
1166 for(int32_t j=0; j<16; j+=2)
1167 if(((k+j)/2)%2)
1168 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1169 }
1170 else
1171 {
1172 for(int32_t i=0; i<4; i++)
1173 {
1174 if (!(bridgedetected & (1<<i)))
1175 {
1176 int32_t tx=((i&2)<<2)+x;
1177 int32_t ty=((i&1)<<3)+y;
1178 for(int32_t k=0; k<8; k+=2)
1179 for(int32_t j=0; j<8; j+=2)
1180 if(((k+j)/2)%2)
1181 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1182 }
1183 }
1184 }
1185 }
1186
1187 if(c.type == cSLOPE)
1188 {
1189 slope_info s(c, x, y);
1190 s.draw(dest, 0, 0, COLOR_SLOPE);
1191 }
1192 auto fl0 = MAPFLAG2(-1,cx,cy);
1193 auto fl1 = MAPFLAG2(0,cx,cy);
1194 auto fl2 = MAPFLAG2(1,cx,cy);
1195 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1196 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1197 {
1198 bool top = false;
1199 if(cy)
1200 {
1201 top = true;
1202 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1203 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1204 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1205 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1206 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1207 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1208 {
1209 top = false;
1210 }
1211 }
1212 draw_ladder(dest,x,y,COLOR_LADDER,top);
1213 }
1214 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1215 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1216 {
1217 draw_platform(dest,x,y,COLOR_LADDER);
1218 }
1219 }
1220
1221 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1222 {
1223 int32_t cx = COMBOX(pos);
1224 int32_t cy = COMBOY(pos);
1225
1226 if (screen < 0) return;
1227 if (map < 0) return;
1228
1229 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1230
1231 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1232
1233 int32_t bridgedetected = 0;
1234 for(int32_t i=0; i<4; i++)
1235 {
1236 int32_t tx=((i&2)<<2)+x;
1237 int32_t ty=((i&1)<<3)+y;
1238 int32_t tx2=((i&2)<<2)+cx;
1239 int32_t ty2=((i&1)<<3)+cy;
1240 for (int32_t m = layer; m <= 1; m++)
1241 {
1242 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1243 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1244 {
1245 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1246 {
1247 bridgedetected |= (1<<i);
1248 }
1249 }
1250 else
1251 {
1252 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1253 {
1254 bridgedetected |= (1<<i);
1255 }
1256 }
1257 }
1258 if (bridgedetected & (1<<i))
1259 {
1260 continue;
1261 }
1262 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1263 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1264
1265
1266 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1267 {
1268 for(int32_t k=0; k<8; k+=2)
1269 for(int32_t j=0; j<8; j+=2)
1270 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1271 }
1272 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1273 {
1274 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1275 {
1276 for(int32_t k=0; k<8; k+=2)
1277 for(int32_t j=0; j<8; j+=2)
1278 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1279 }
1280 else
1281 {
1282 int32_t color = COLOR_SOLID;
1283
1284 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1285 color=vc(6);
1286 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1287 color=vc(7);
1288
1289 rectfill(dest,tx,ty,tx+7,ty+7,color);
1290 }
1291 }
1292 }
1293
1294 bridgedetected = 0;
1295 for(int32_t i=0; i<4; i++)
1296 {
1297 int32_t tx2=((i&2)<<2)+cx;
1298 int32_t ty2=((i&1)<<3)+cy;
1299 for (int32_t m = 0; m <= 1; m++)
1300 {
1301 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1302 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1303 {
1304 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1305 {
1306 bridgedetected |= (1<<i);
1307 }
1308 }
1309 else
1310 {
1311 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1312 {
1313 bridgedetected |= (1<<i);
1314 }
1315 }
1316 }
1317 }
1318
1319 // Draw damage combos
1320 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1321 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1322 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1323 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1324 || combo_class_buf[c1.type].modify_hp_amount
1325 || combo_class_buf[c2.type].modify_hp_amount;
1326
1327 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1328
1329 if(dmg)
1330 {
1331 if (bridgedetected <= 0)
1332 {
1333 for(int32_t k=0; k<16; k+=2)
1334 for(int32_t j=0; j<16; j+=2)
1335 if(((k+j)/2)%2)
1336 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1337 }
1338 else
1339 {
1340 for(int32_t i=0; i<4; i++)
1341 {
1342 if (!(bridgedetected & (1<<i)))
1343 {
1344 int32_t tx=((i&2)<<2)+x;
1345 int32_t ty=((i&1)<<3)+y;
1346 for(int32_t k=0; k<8; k+=2)
1347 for(int32_t j=0; j<8; j+=2)
1348 if(((k+j)/2)%2)
1349 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1350 }
1351 }
1352 }
1353 }
1354
1355 if(c.type == cSLOPE)
1356 {
1357 slope_info s(c, x, y);
1358 s.draw(dest, 0, 0, COLOR_SLOPE);
1359 }
1360 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1361 auto fl1 = MAPFLAG3(map,screen,0,pos);
1362 auto fl2 = MAPFLAG3(map,screen,1,pos);
1363 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1364 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1365 {
1366 bool top = false;
1367 if(cy)
1368 {
1369 top = true;
1370 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1371 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1372 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1373 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1374 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1375 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1376 {
1377 top = false;
1378 }
1379 }
1380 draw_ladder(dest,x,y,COLOR_LADDER,top);
1381 }
1382 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1383 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1384 {
1385 draw_platform(dest,x,y,COLOR_LADDER);
1386 }
1387 }
1388
1389 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1390 {
1391 const newcombo& c = combobuf[cmbdat];
1392
1393 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1394
1395 for(int32_t i=0; i<4; i++)
1396 {
1397 int32_t tx=((i&2)<<2)+x;
1398 int32_t ty=((i&1)<<3)+y;
1399
1400 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1401 {
1402 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1403 {
1404 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1405 }
1406 else
1407 {
1408 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1409 }
1410 }
1411
1412
1413 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1414 {
1415 for(int32_t k=0; k<8; k+=2)
1416 for(int32_t j=0; j<8; j+=2)
1417 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1418 }
1419 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1420 {
1421 if(c.type==cLADDERHOOKSHOT)
1422 {
1423 for(int32_t k=0; k<8; k+=2)
1424 for(int32_t j=0; j<8; j+=2)
1425 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1426 }
1427 else
1428 {
1429 int32_t color = COLOR_SOLID;
1430
1431 if(c.type==cLADDERONLY)
1432 color=vc(6);
1433 else if(c.type==cHOOKSHOTONLY)
1434 color=vc(7);
1435
1436 rectfill(dest,tx,ty,tx+7,ty+7,color);
1437 }
1438 }
1439
1440 // Draw damage combos
1441 if(combo_class_buf[c.type].modify_hp_amount != 0)
1442 {
1443 for(int32_t k=0; k<8; k+=2)
1444 for(int32_t j=0; j<8; j+=2)
1445 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1446 }
1447 }
1448
1449 if(c.type == cSLOPE)
1450 {
1451 slope_info s(c, 0, 0);
1452 zfix const& slope = s.slope();
1453
1454 BITMAP* sub = create_bitmap_ex(8,16,16);
1455 clear_bitmap(sub);
1456 s.draw(sub, 0, 0, COLOR_SLOPE);
1457 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1458 destroy_bitmap(sub);
1459 }
1460 if(c.flag == mfSIDEVIEWLADDER)
1461 {
1462 draw_ladder(dest,x,y,COLOR_LADDER);
1463 }
1464 else if(c.flag == mfSIDEVIEWPLATFORM)
1465 {
1466 draw_platform(dest,x,y,COLOR_LADDER);
1467 }
1468 }
1469
1470 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1471 {
1472 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1473 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1474 }
1475 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1476 {
1477
1478 newcombo const& c = combobuf[cmbdat];
1479
1480 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1481 {
1482 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1483 // text_mode(-1);
1484 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1485 if(sflag)
1486 {
1487 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1488 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1489 }
1490
1491 if(c.flag)
1492 {
1493 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1494 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1495 }
1496 }
1497
1498 if(flags&cCSET)
1499 {
1500 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1501 // text_mode(inv?vc(15):vc(0));
1502 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1503 }
1504 else if(flags&cCTYPE)
1505 {
1506 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1507 // text_mode(inv?vc(15):vc(0));
1508 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1509 }
1510 }
1511
1512 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1513 {
1514 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1515
1516 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1517 if(repos)
1518 {
1519 combotile_override_x = x+(8*(scale-1));
1520 combotile_override_y = y+(8*(scale-1));
1521 }
1522 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1523 if(repos) combotile_override_x = combotile_override_y = -1;
1524 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1525 destroy_bitmap(b);
1526 }
1527 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1528 {
1529 static newcombo nilcombo;
1530 nilcombo.tile = 0;
1531
1532 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1533
1534 if(c.tile==0)
1535 {
1536 rectfill(dest,x,y,x+15,y+15,vc(0));
1537 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1538 return;
1539 }
1540
1541 putcombo(dest,x,y,cmbdat,cset);
1542
1543 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1544 {
1545 if(sflag)
1546 {
1547 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1548 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1549 }
1550
1551 if(combobuf[cmbdat].flag)
1552 {
1553 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1554 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1555 }
1556 }
1557
1558 if(flags&cWALK)
1559 {
1560 put_walkflags(dest,x,y,cmbdat,0);
1561 }
1562
1563 if(flags&cCSET)
1564 {
1565 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1566 // text_mode(inv?vc(15):vc(0));
1567 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1568 }
1569 else if(flags&cCTYPE)
1570 {
1571 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1572 // text_mode(inv?vc(15):vc(0));
1573 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1574 }
1575 }
1576 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1577 {
1578 auto blitx = 1 + (slot % 16) * 17;
1579 auto blity = 1 + (slot / 16) * 17;
1580 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1581 }
1582
1583
1584 void copy_mapscr(mapscr *dest, const mapscr *src)
1585 {
1586 if(!dest || !src) return;
1587 *dest = *src;
1588 }
1589
1590 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1591 {
1592 int32_t x=0,y=0;
1593 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1594
1595 switch(side)
1596 {
1597 case up:
1598 case down:
1599 x=((pos&15)<<4)+xofs;
1600 y=(ignorepos?0:(pos&0xF0))+yofs;
1601 break;
1602
1603 case left:
1604 case right:
1605 x=(ignorepos?0:((pos&15)<<4))+xofs;
1606 y=(pos&0xF0)+yofs;
1607 break;
1608 }
1609
1610 switch(type)
1611 {
1612 case dt_lock:
1613 case dt_shut:
1614 case dt_boss:
1615 case dt_bomb:
1616 switch(side)
1617 {
1618 case up:
1619 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1620 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1621 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1622 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1623 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1624 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1625 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1626 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1627 break;
1628
1629 case down:
1630 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1631 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1632 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1633 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1634 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1635 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1636 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1637 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1638 break;
1639
1640 case left:
1641 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1642 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1643 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1644 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1645 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1646 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1647
1648 if(x+16 >= dest->w)
1649 break;
1650
1651 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1653 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1655 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1656 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1657 break;
1658
1659 case right:
1660
1661 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1663 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1665 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1666 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1667
1668 if(x+16 <= 0)
1669 break;
1670
1671 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1673 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1675 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1676 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1677 break;
1678 }
1679
1680 break;
1681
1682 case dt_pass:
1683 case dt_wall:
1684 case dt_walk:
1685 default:
1686 break;
1687 }
1688 }
1689
1690 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1691 {
1692 int32_t x=((pos&15)<<4)+xofs;
1693 int32_t y=(pos&0xF0)+yofs;
1694 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1695
1696
1697 switch(side)
1698 {
1699 case up:
1700 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1701 {
1702 overcombo(dest,x,y,
1703 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1705 }
1706
1707 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1708 {
1709 overcombo(dest,x+16,y,
1710 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1711
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1713 }
1714
1715 break;
1716
1717 case down:
1718 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1719 {
1720 overcombo(dest,x,y,
1721 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1723 }
1724
1725 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1726 {
1727 overcombo(dest,x+16,y,
1728 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1730 }
1731
1732 break;
1733
1734 case left:
1735 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1736 {
1737 overcombo(dest,x,y,
1738 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1740 }
1741
1742 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1743 {
1744 overcombo(dest,x,y+16,
1745 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1747 }
1748
1749 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1750 {
1751 overcombo(dest,x,y+32,
1752 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1754 }
1755
1756 break;
1757
1758 case right:
1759 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1760 {
1761 overcombo(dest,x,y,
1762 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1764 }
1765
1766 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1767 {
1768 overcombo(dest,x,y+16,
1769
1770 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1772 }
1773
1774 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1775 {
1776 overcombo(dest,x,y+32,
1777 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1779 }
1780
1781 break;
1782 }
1783 }
1784
1785 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1786 {
1787 word cmbcheck1, cmbcheck2;
1788 newcombo combocheck1, combocheck2;
1789 combocheck1 = combobuf[0];
1790 combocheck2 = combobuf[0];
1791 combocheck1.walk = 0;
1792 combocheck2.walk = 0;
1793
1794 int32_t layermap, layerscreen;
1795
1796 switch(dir)
1797 {
1798 case up:
1799 {
1800 if(i>15) //not top row of combos
1801 {
1802 return false;
1803 }
1804
1805 if(screen<16) //top row of screens
1806 {
1807 return false;
1808
1809 }
1810
1811 //check main screen
1812 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1813 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1814 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1815 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1816
1817 //check layer 1
1818 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1819
1820 if(layermap>-1 && layermap<map_count)
1821 {
1822 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1823 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1824 if (combobuf[cmbcheck1].type == cBRIDGE)
1825 {
1826 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1827 {
1828 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1829 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1830 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1831 }
1832 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1833 }
1834 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1835 }
1836
1837 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1838
1839 if(layermap>-1 && layermap<map_count)
1840 {
1841 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1842 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1843 if (combobuf[cmbcheck2].type == cBRIDGE)
1844 {
1845 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1846 {
1847 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1848 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1849 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1850 }
1851 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1852 }
1853 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1854 }
1855
1856 //check layer 2
1857 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1858
1859 if(layermap>-1 && layermap<map_count)
1860 {
1861 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1862
1863 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1864 if (combobuf[cmbcheck2].type == cBRIDGE)
1865 {
1866 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1867 {
1868 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1869 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1870 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1871 }
1872 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1873 }
1874 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1875 }
1876
1877 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1878
1879 if(layermap>-1 && layermap<map_count)
1880 {
1881 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1882 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1883 if (combobuf[cmbcheck2].type == cBRIDGE)
1884 {
1885 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1886 {
1887 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1888 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1889 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1890 }
1891 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1892 }
1893 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1894 }
1895
1896 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1897 {
1898 return true;
1899 }
1900
1901 break;
1902 }
1903 case down:
1904 {
1905 if(i<160) //not bottom row of combos
1906 {
1907 return false;
1908 }
1909
1910 if(screen>111) //bottom row of screens
1911 {
1912 return false;
1913 }
1914
1915 //check main screen
1916 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1917 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1918 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1919 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1920
1921
1922 //check layer 1
1923 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1924
1925 if(layermap>-1 && layermap<map_count)
1926 {
1927 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1928 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1929 if (combobuf[cmbcheck1].type == cBRIDGE)
1930 {
1931 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1932 {
1933 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1934 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1935 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1936 }
1937 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1938 }
1939 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1940 }
1941
1942 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1943
1944 if(layermap>-1 && layermap<map_count)
1945 {
1946 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1947 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1948 if (combobuf[cmbcheck2].type == cBRIDGE)
1949 {
1950 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1951 {
1952 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1953 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1954 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1955 }
1956 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1957 }
1958 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1959 }
1960
1961 //check layer 2
1962 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1963
1964 if(layermap>-1 && layermap<map_count)
1965 {
1966 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1967 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1968 if (combobuf[cmbcheck1].type == cBRIDGE)
1969 {
1970 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1971 {
1972 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1973 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1974 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1975 }
1976 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1977 }
1978 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1979 }
1980
1981 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1982
1983 if(layermap>-1 && layermap<map_count)
1984 {
1985 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1986 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1987 if (combobuf[cmbcheck2].type == cBRIDGE)
1988 {
1989 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1990 {
1991 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1992 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1993 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1994 }
1995 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1996 }
1997 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1998 }
1999
2000 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2001 {
2002 return true;
2003 }
2004
2005 break;
2006 }
2007 case left:
2008 {
2009 if((i&0xF)!=0) //not left column of combos
2010 {
2011 return false;
2012 }
2013
2014 if((screen&0xF)==0) //left column of screens
2015 {
2016 return false;
2017 }
2018
2019 //check main screen
2020 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2021 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2022 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2023 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2024
2025 //check layer 1
2026 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2027
2028 if(layermap>-1 && layermap<map_count)
2029 {
2030 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2031 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2032 if (combobuf[cmbcheck1].type == cBRIDGE)
2033 {
2034 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2035 {
2036 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2037 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2038 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2039 }
2040 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2041 }
2042 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2043 }
2044
2045 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2046
2047 if(layermap>-1 && layermap<map_count)
2048 {
2049 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2050 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2051 if (combobuf[cmbcheck2].type == cBRIDGE)
2052 {
2053 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2054 {
2055 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2056 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2057 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2058 }
2059 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2060 }
2061 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2062 }
2063
2064 //check layer 2
2065 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2066
2067 if(layermap>-1 && layermap<map_count)
2068 {
2069 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2070 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2071 if (combobuf[cmbcheck1].type == cBRIDGE)
2072 {
2073 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2074 {
2075 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2076 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2077 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2078 }
2079 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2080 }
2081 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2082 }
2083
2084 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2085
2086 if(layermap>-1 && layermap<map_count)
2087 {
2088 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2089 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2090 if (combobuf[cmbcheck2].type == cBRIDGE)
2091 {
2092 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2093 {
2094 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2095 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2096 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2097 }
2098 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2099 }
2100 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2101 }
2102
2103 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2104 {
2105 return true;
2106 }
2107
2108 break;
2109 }
2110 case right:
2111 {
2112 if((i&0xF)!=15) //not right column of combos
2113 {
2114 return false;
2115 }
2116
2117 if((screen&0xF)==15) //right column of screens
2118 {
2119 return false;
2120 }
2121
2122 //check main screen
2123 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2124 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2125 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2126 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2127
2128 //check layer 1
2129 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2130
2131 if(layermap>-1 && layermap<map_count)
2132 {
2133 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2134 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2135 if (combobuf[cmbcheck1].type == cBRIDGE)
2136 {
2137 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2138 {
2139 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2140 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2141 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2142 }
2143 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2144 }
2145 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2146 }
2147
2148 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2149
2150 if(layermap>-1 && layermap<map_count)
2151 {
2152 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2153 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2154 if (combobuf[cmbcheck2].type == cBRIDGE)
2155 {
2156 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2157 {
2158 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2159 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2160 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2161 }
2162 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2163 }
2164 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2165 }
2166
2167 //check layer 2
2168 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2169
2170 if(layermap>-1 && layermap<map_count)
2171 {
2172 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2173 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2174 if (combobuf[cmbcheck1].type == cBRIDGE)
2175 {
2176 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2177 {
2178 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2179 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2180 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2181 }
2182 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2183 }
2184 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2185 }
2186
2187 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2188
2189 if(layermap>-1 && layermap<map_count)
2190 {
2191 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2192
2193 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2194 if (combobuf[cmbcheck2].type == cBRIDGE)
2195 {
2196 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2197 {
2198 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2199 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2200 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2201 }
2202 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2203 }
2204 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2205 }
2206
2207 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2208 {
2209 return true;
2210 }
2211
2212 break;
2213 }
2214 }
2215
2216 return false;
2217 }
2218
2219 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2220 {
2221 int32_t checkcombo;
2222
2223 if(alignment_arrow_timer>31)
2224 {
2225 if(scr<0)
2226 {
2227 scr=cursor.screen;
2228 }
2229
2230 if((scr<128)) //do the misalignment arrows
2231 {
2232 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2233 {
2234 if(misaligned(cursor.map, scr, checkcombo, up))
2235 {
2236 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2237 }
2238 }
2239
2240 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2241 {
2242 if(misaligned(cursor.map, scr, checkcombo, down))
2243 {
2244 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 }
2246 }
2247
2248 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2249 {
2250 if(misaligned(cursor.map, scr, checkcombo, left))
2251 {
2252 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 }
2254 }
2255
2256 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2257 {
2258 if(misaligned(cursor.map, scr, checkcombo, right))
2259 {
2260 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2261 }
2262 }
2263
2264 int32_t tempalign;
2265
2266 //check top left corner
2267 checkcombo=0;
2268 tempalign=0;
2269 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2270 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2271
2272 switch(tempalign)
2273 {
2274 case 0:
2275 break;
2276
2277 case 1: //up
2278 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2279 break;
2280
2281 case 2: //left
2282 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2283 break;
2284
2285 case 3: //up-left
2286 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2287 break;
2288 }
2289
2290 //check top right corner
2291 checkcombo=15;
2292 tempalign=0;
2293 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2294 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2295
2296 switch(tempalign)
2297 {
2298 case 0:
2299 break;
2300
2301 case 1: //up
2302 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2303 break;
2304
2305 case 2: //right
2306 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2307 break;
2308
2309 case 3: //up-right
2310 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2311 break;
2312 }
2313
2314 //check bottom left corner
2315 checkcombo=160;
2316 tempalign=0;
2317 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2318 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2319
2320 switch(tempalign)
2321 {
2322 case 0:
2323 break;
2324
2325 case 1: //down
2326 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2327 break;
2328
2329 case 2: //left
2330 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2331 break;
2332
2333 case 3: //down-left
2334 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2335 break;
2336 }
2337
2338 //check bottom right corner
2339
2340 checkcombo=175;
2341 tempalign=0;
2342 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2343 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2344
2345 switch(tempalign)
2346 {
2347 case 0:
2348 break;
2349
2350 case 1: //down
2351 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2352 break;
2353
2354 case 2: //right
2355 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2356 break;
2357
2358 case 3: //down-right
2359 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2360 break;
2361 }
2362 }
2363 }
2364 }
2365
2366 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2367 {
2368 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2369 }
2370
2371 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2372 {
2373 if (map < 0 || screen < 0) return 0;
2374
2375 if(pos>175 || pos < 0)
2376 return 0;
2377
2378 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2379
2380 if (!m->is_valid()) return 0;
2381
2382 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2383
2384 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2385
2386 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2387
2388 if (!scr->is_valid()) return 0;
2389
2390 return scr->data[pos]; // entire combo code
2391 }
2392
2393 // Takes array index layer num., not actual layer num.
2394 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2395 {
2396 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2397
2398 if(map<0)
2399 map=cursor.map;
2400
2401 if(scr<0)
2402 scr=cursor.screen;
2403
2404 mapscr *screen1;
2405
2406 if(prv_mode)
2407 {
2408 screen1=get_prvscr();
2409 }
2410 else
2411 {
2412 screen1=AbsoluteScr(cursor.map,cursor.screen);
2413 }
2414
2415 int32_t layermap;
2416 layermap=screen1->layermap[lyr]-1;
2417
2418 if(layermap<0 || layermap >= map_count) return 0;
2419
2420 mapscr *layer;
2421
2422 if(prv_mode)
2423 layer = &prvlayers[lyr];
2424 else
2425 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2426
2427 int32_t pos = COMBOPOS(x,y);
2428
2429 if(pos>175 || pos < 0)
2430 return 0;
2431
2432 return layer->data[pos];
2433 }
2434
2435 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2436 {
2437 if(map<0)
2438 map=cursor.map;
2439
2440 if(scr<0)
2441 scr=cursor.screen;
2442
2443 mapscr *screen1;
2444
2445 if(prv_mode)
2446 {
2447 screen1=get_prvscr();
2448 }
2449 else
2450 {
2451 screen1=AbsoluteScr(cursor.map,cursor.screen);
2452 }
2453
2454 x = vbound(x, 0, 16*16);
2455 y = vbound(y, 0, 11*16);
2456 int32_t combo = COMBOPOS(x,y);
2457
2458 if(combo>175 || combo < 0)
2459 return 0;
2460
2461 return screen1->data[combo];
2462 }
2463
2464 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2465 {
2466 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2467 }
2468
2469 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2470 {
2471 if (map < 0 || screen < 0) return 0;
2472
2473 if(pos>175 || pos < 0)
2474 return 0;
2475
2476 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2477
2478 if (!m->is_valid()) return 0;
2479
2480 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2481
2482 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2483
2484 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2485
2486 if (!scr->is_valid()) return 0;
2487
2488 return scr->sflag[pos]; // entire combo code
2489 }
2490
2491 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2492 {
2493 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2494
2495 if(map<0)
2496 map=cursor.map;
2497
2498 if(scr<0)
2499 scr=cursor.screen;
2500
2501 mapscr *screen1;
2502
2503 if(prv_mode)
2504 {
2505 screen1=get_prvscr();
2506 }
2507 else
2508 {
2509 screen1=AbsoluteScr(cursor.map,cursor.screen);
2510 }
2511
2512 int32_t layermap;
2513 layermap=screen1->layermap[lyr]-1;
2514
2515 if(layermap<0 || layermap >= map_count) return 0;
2516
2517 mapscr *layer;
2518
2519 if(prv_mode)
2520 layer = &prvlayers[lyr];
2521 else
2522 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2523
2524 int32_t combo = COMBOPOS(x,y);
2525
2526 if(combo>175 || combo < 0)
2527 return 0;
2528
2529 return layer->sflag[combo];
2530 }
2531
2532 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2533 {
2534 if(map<0)
2535 map=cursor.map;
2536
2537 if(scr<0)
2538 scr=cursor.screen;
2539
2540 mapscr *screen1;
2541
2542 if(prv_mode)
2543 {
2544 screen1=get_prvscr();
2545 }
2546 else
2547 {
2548 screen1=AbsoluteScr(cursor.map,cursor.screen);
2549 }
2550
2551 x = vbound(x, 0, 16*16);
2552 y = vbound(y, 0, 11*16);
2553 int32_t combo = COMBOPOS(x,y);
2554
2555 if(combo>175 || combo < 0)
2556 return 0;
2557
2558 return screen1->sflag[combo];
2559 }
2560
2561 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2562 {
2563 mapscr *layers[7];
2564 mapscr *basescr;
2565 if(prv_mode)
2566 {
2567 layers[0] = &prvscr;
2568 basescr = layers[0];
2569 for(auto q = 1; q < 7; ++q)
2570 {
2571 if(prvlayers[q-1].valid)
2572 layers[q] = &(prvlayers[q-1]);
2573 else layers[q] = NULL;
2574 }
2575 }
2576 else
2577 {
2578 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2579 basescr = layers[0];
2580 for(auto q = 1; q < 7; ++q)
2581 {
2582 int32_t lmap = basescr->layermap[q-1]-1;
2583 int32_t lscr = basescr->layerscreen[q-1];
2584 if(lmap < 0)
2585 layers[q] = NULL;
2586 else layers[q] = AbsoluteScr(lmap, lscr);
2587 }
2588 }
2589 for(auto q = 0; q < 7; ++q)
2590 {
2591 if(!layers[q]) continue;
2592 for(auto pos = 0; pos < 176; ++pos)
2593 {
2594 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2595 if(cmb.type == cTORCH)
2596 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2597 }
2598 }
2599 word maxffc = basescr->numFFC();
2600 for(auto q = 0; q < maxffc; ++q)
2601 {
2602 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2603 if(cmb.type == cTORCH)
2604 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2605 }
2606 }
2607
2608 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2609 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2610 {
2611 newcombo const& cmb = combobuf[cid];
2612 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2613 if(dither)
2614 {
2615 if (LayerDitherSz == 0)
2616 return;
2617 BITMAP* buf = create_bitmap_ex(8,16,16);
2618 clear_bitmap(buf);
2619 overcombo(buf,0,0,cid,cset);
2620 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2621 if(over)
2622 {
2623 if(transp)
2624 {
2625 color_map = &trans_table2;
2626 draw_trans_sprite(dest, buf, x, y);
2627 color_map = &trans_table;
2628 }
2629 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2630 }
2631 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2632 destroy_bitmap(buf);
2633 }
2634 else if(over)
2635 {
2636 if(transp)
2637 overcombotranslucent(dest,x,y,cid,cset,0);
2638 else overcombo(dest,x,y,cid,cset);
2639 }
2640 else put_combo(dest,x,y,cid,cset,flags,sflag);
2641 }
2642 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2643 {
2644 if(!md) return;
2645 for (int32_t i = 0; i < 176; i++)
2646 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2647 }
2648 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2649 {
2650 if(!md) return;
2651 for (int32_t i = 0; i < 176; i++)
2652 {
2653 int data = md->data[i];
2654 if(combo_class_buf[combobuf[data].type].overhead)
2655 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2656 }
2657 }
2658 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2659 {
2660 if(!LayerMaskInt[lyr])
2661 return nullptr;
2662 if(lyr == 0)
2663 return basescr;
2664 int layermap = basescr->layermap[lyr-1]-1;
2665
2666 if(layermap>-1 && layermap<map_count)
2667 {
2668 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2669 return &TheMaps[layerscreen];
2670 }
2671 return nullptr;
2672 }
2673 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2674 {
2675 int num_ffcs = basescr->numFFC();
2676 for(int32_t i=num_ffcs-1; i>=0; i--)
2677 {
2678 auto const& ff = basescr->ffcs[i];
2679 if(ff.data)
2680 {
2681 if(!(ff.flags&ffc_changer))
2682 {
2683 int32_t tx=(ff.x.getInt())+x;
2684 int32_t ty=(ff.y.getInt())+y;
2685
2686 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2687 {
2688 if(ff.flags&ffc_trans)
2689 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2690 else
2691 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2692 }
2693 }
2694 }
2695 }
2696 }
2697 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2698 {
2699 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2700 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2701
2702 if(map<0)
2703 map=cursor.map;
2704
2705 if(screen<0)
2706 screen=cursor.screen;
2707
2708 mapscr *basescr;
2709 mapscr* layers[7] = {nullptr};
2710
2711 if(prv_mode)
2712 {
2713 hl_layer = -1;
2714 basescr=get_prvscr();
2715 }
2716 else
2717 {
2718 basescr=AbsoluteScr(map,screen);
2719 }
2720 layers[0] = _zmap_get_lyr_checked(0,basescr);
2721 for(int lyr = 1; lyr < 7; ++lyr)
2722 {
2723 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2724 : _zmap_get_lyr_checked(lyr,basescr);
2725 }
2726
2727 if(!(basescr->valid&mVALID))
2728 {
2729 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2730 rectfill(dest,x,y,x+255,y+175,vc(1));
2731
2732 if(ShowMisalignments)
2733 {
2734 check_alignments(dest,x,y,screen);
2735 }
2736
2737 return;
2738 }
2739
2740 if(LayerMaskInt[0]==0)
2741 {
2742 byte bgfill = 0;
2743 if (LayerDitherBG > -1)
2744 bgfill = vc(LayerDitherBG);
2745 rectfill(dest,x,y,x+255,y+175,bgfill);
2746 }
2747
2748 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2749 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2750 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2751
2752 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2753 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2754 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2755
2756 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2757 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2758
2759 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2760 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2761
2762 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2763 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2764 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2765
2766 int32_t doortype[4];
2767
2768 for(int32_t i=0; i<4; i++)
2769 {
2770 switch(basescr->door[i])
2771 {
2772 case dOPEN:
2773 doortype[i]=dt_pass;
2774 break;
2775
2776 case dLOCKED:
2777 doortype[i]=dt_lock;
2778 break;
2779
2780 case d1WAYSHUTTER:
2781 case dSHUTTER:
2782 doortype[i]=dt_shut;
2783 break;
2784
2785 case dBOSS:
2786 doortype[i]=dt_boss;
2787 break;
2788
2789 case dBOMB:
2790 doortype[i]=dt_bomb;
2791 break;
2792 }
2793 }
2794
2795 switch(basescr->door[up])
2796 {
2797 case dBOMB:
2798 over_door(dest,39,up,x,y,false, screen);
2799 [[fallthrough]];
2800 case dOPEN:
2801 case dLOCKED:
2802 case d1WAYSHUTTER:
2803 case dSHUTTER:
2804 case dBOSS:
2805 put_door(dest,7,up,doortype[up],x,y,false,screen);
2806 break;
2807
2808 case dWALK:
2809 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2810 {
2811 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2812 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2813 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2814 }
2815 else
2816
2817 {
2818 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2819 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2820 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2821 }
2822
2823 break;
2824 }
2825
2826 switch(basescr->door[down])
2827 {
2828 case dBOMB:
2829 over_door(dest,135,down,x,y,false,screen);
2830 [[fallthrough]];
2831 case dOPEN:
2832 case dLOCKED:
2833 case d1WAYSHUTTER:
2834 case dSHUTTER:
2835 case dBOSS:
2836 put_door(dest,151,down,doortype[down],x,y,false,screen);
2837 break;
2838
2839 case dWALK:
2840 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2841 {
2842 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2843 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2844 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2845 }
2846 else
2847 {
2848 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2849 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2850 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2851 }
2852
2853 break;
2854 }
2855
2856 switch(basescr->door[left])
2857 {
2858 case dBOMB:
2859 over_door(dest,66,left,x,y,false,screen);
2860 [[fallthrough]];
2861 case dOPEN:
2862 case dLOCKED:
2863 case d1WAYSHUTTER:
2864 case dSHUTTER:
2865 case dBOSS:
2866 put_door(dest,64,left,doortype[left],x,y,false,screen);
2867 break;
2868
2869 case dWALK:
2870 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2871 {
2872 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2873 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2874 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2875 }
2876 else
2877 {
2878 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2879 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2880 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2881 }
2882
2883 break;
2884 }
2885
2886 switch(basescr->door[right])
2887 {
2888
2889 case dBOMB:
2890 over_door(dest,77,right,x,y,false,screen);
2891 [[fallthrough]];
2892 case dOPEN:
2893 case dLOCKED:
2894 case d1WAYSHUTTER:
2895 case dSHUTTER:
2896 case dBOSS:
2897 put_door(dest,78,right,doortype[right],x,y,false,screen);
2898 break;
2899
2900 case dWALK:
2901 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2902 {
2903 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2904 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2905 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2906 }
2907 else
2908 {
2909 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2910 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2911 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2912 }
2913
2914 break;
2915 }
2916
2917 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2918 {
2919 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2920 }
2921
2922 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2923 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2924 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2925
2926 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2927 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2928
2929 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2930
2931 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2932 {
2933 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2934 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2935 }
2936 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2937 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2938
2939 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2940
2941 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2942 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2943 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2944
2945 int num_ffcs = basescr->numFFC();
2946 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2947 if(basescr->ffcs[i].data)
2948 if(basescr->ffcs[i].flags&ffc_changer)
2949 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2950
2951 if(flags&cWALK)
2952 {
2953 if(layers[0])
2954 for(int32_t i=0; i<176; i++)
2955 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2956
2957 for(int32_t k=0; k<2; k++)
2958 {
2959 if(layers[k+1])
2960 for(int32_t i=0; i<176; i++)
2961 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2962 }
2963 for(int32_t i=num_ffcs-1; i>=0; i--)
2964 {
2965 if(auto data = basescr->ffcs[i].data)
2966 {
2967 if(!(basescr->ffcs[i].flags&ffc_changer))
2968 {
2969 newcombo const& cmb = combobuf[data];
2970 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2971 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2972
2973 if(basescr->ffcs[i].flags&ffc_solid)
2974 {
2975 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2976 }
2977
2978 if(cmb.type == cSLOPE)
2979 {
2980 slope_info s(cmb, tx, ty);
2981 s.draw(dest, 0, 0, COLOR_SLOPE);
2982 }
2983 }
2984 }
2985 }
2986 }
2987
2988 if(flags&cFLAGS)
2989 {
2990 if(LayerMaskInt[CurrentLayer]!=0)
2991 {
2992 for(int32_t i=0; i<176; i++)
2993 {
2994 if(CurrentLayer==0)
2995 {
2996 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2997 }
2998 else
2999 {
3000 if(prv_mode)
3001 {
3002 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3003 }
3004 else if(basescr->layermap[CurrentLayer-1] > 0)
3005 {
3006 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3007
3008 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3009 {
3010 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3011 TheMaps[_lscr].data[i],
3012 TheMaps[_lscr].cset[i], flags,
3013 TheMaps[_lscr].sflag[i]);
3014 }
3015 }
3016 }
3017 }
3018 }
3019 }
3020
3021 int32_t dark = basescr->flags&cDARK;
3022
3023 if(dark && !(flags&cNODARK)
3024 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3025 {
3026 for(int32_t j=0; j<80; j++)
3027 {
3028 for(int32_t i=0; i<(80)-j; i++)
3029 {
3030 if(((i^j)&1)==0)
3031 {
3032 putpixel(dest,x+i,y+j,vc(blackout_color));
3033 }
3034 }
3035 }
3036 }
3037
3038 if(ShowMisalignments)
3039 {
3040 check_alignments(dest,x,y,screen);
3041 }
3042 }
3043
3044 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3045 {
3046 if(map<0)
3047 map=cursor.map;
3048
3049 if(scr<0)
3050 scr=cursor.screen;
3051
3052 mapscr* layer=AbsoluteScr(map,scr);
3053 int32_t layermap=0, layerscreen=0;
3054
3055 if(!(layer->valid&mVALID))
3056 {
3057 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3058 rectfill(dest,x,y,x+255,y+15,vc(1));
3059 return;
3060 }
3061
3062 int32_t dark = layer->flags&4;
3063
3064 if(LayerMaskInt[0]==0)
3065 {
3066 rectfill(dest,x,y,x+255,y+15,0);
3067 }
3068
3069
3070 for(int32_t k=1; k<3; k++)
3071 {
3072 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3073 {
3074 layermap=layer->layermap[k]-1;
3075
3076 if(layermap>-1 && layermap<map_count)
3077 {
3078 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3079
3080 for(int32_t i=c; i<(c&0xF0)+16; i++)
3081 {
3082 auto data = TheMaps[layerscreen].data[i];
3083 auto cs = TheMaps[layerscreen].cset[i];
3084 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3085 }
3086 }
3087 }
3088 }
3089
3090 if(LayerMaskInt[0]!=0)
3091 {
3092 for(int32_t i=c; i<(c&0xF0)+16; i++)
3093 {
3094 word cmbdat = (i < 176 ? layer->data[i] : 0);
3095 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3096 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3097 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3098 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3099 }
3100 }
3101
3102 for(int32_t k=0; k<2; k++)
3103 {
3104 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3105 {
3106 layermap=layer->layermap[k]-1;
3107
3108 if(layermap>-1 && layermap<map_count)
3109 {
3110 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3111
3112 for(int32_t i=c; i<(c&0xF0)+16; i++)
3113 {
3114 auto data = TheMaps[layerscreen].data[i];
3115 auto cs = TheMaps[layerscreen].cset[i];
3116 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3117 }
3118 }
3119 }
3120 }
3121
3122 int32_t doortype[4];
3123
3124 for(int32_t i=0; i<4; i++)
3125 {
3126 switch(layer->door[i])
3127 {
3128 case dOPEN:
3129 doortype[i]=dt_pass;
3130 break;
3131
3132 case dLOCKED:
3133 doortype[i]=dt_lock;
3134 break;
3135
3136 case d1WAYSHUTTER:
3137 case dSHUTTER:
3138 doortype[i]=dt_shut;
3139 break;
3140
3141 case dBOSS:
3142 doortype[i]=dt_boss;
3143 break;
3144
3145 case dBOMB:
3146 doortype[i]=dt_bomb;
3147 break;
3148 }
3149 }
3150
3151 if(c<16)
3152 {
3153 switch(layer->door[up])
3154 {
3155 case dBOMB:
3156 case dOPEN:
3157 case dLOCKED:
3158 case d1WAYSHUTTER:
3159 case dSHUTTER:
3160 case dBOSS:
3161 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3162 break;
3163 }
3164 }
3165 else if(c>159)
3166 {
3167 switch(layer->door[down])
3168 {
3169 case dBOMB:
3170 case dOPEN:
3171 case dLOCKED:
3172 case d1WAYSHUTTER:
3173 case dSHUTTER:
3174 case dBOSS:
3175 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3176 break;
3177 }
3178 }
3179
3180 for(int32_t k=2; k<4; k++)
3181 {
3182 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3183 {
3184 layermap=layer->layermap[k]-1;
3185
3186 if(layermap>-1 && layermap<map_count)
3187 {
3188 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3189
3190 for(int32_t i=c; i<(c&0xF0)+16; i++)
3191 {
3192 if(layer->layeropacity[k]<255)
3193 {
3194 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3195 }
3196 else
3197 {
3198 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3199 }
3200 }
3201 }
3202 }
3203 }
3204
3205 //Overhead L0
3206 if(LayerMaskInt[0]!=0)
3207 {
3208 for(int32_t i=c; i<(c&0xF0)+16; i++)
3209 {
3210 int32_t ct1=layer->data[i];
3211 int32_t ct3=combobuf[ct1].type;
3212
3213 if(combo_class_buf[ct3].overhead)
3214 {
3215 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3216 }
3217 }
3218 }
3219
3220 //Overhead L1/2
3221 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3222 {
3223 for(int32_t k = 0; k < 2; ++k)
3224 {
3225 if(LayerMaskInt[k+1]!=0)
3226 {
3227 layermap=layer->layermap[k]-1;
3228
3229 if(layermap>-1 && layermap<map_count)
3230 {
3231 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3232 for(int32_t i=c; i<(c&0xF0)+16; i++)
3233 {
3234 auto data = TheMaps[layerscreen].data[i];
3235 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3236 auto cs = TheMaps[layerscreen].cset[i];
3237 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3238 }
3239 }
3240 }
3241 }
3242 }
3243
3244 for(int32_t k=4; k<6; k++)
3245 {
3246 if(LayerMaskInt[k+1]!=0)
3247 {
3248 layermap=layer->layermap[k]-1;
3249
3250 if(layermap>-1 && layermap<map_count)
3251 {
3252 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3253
3254 for(int32_t i=c; i<(c&0xF0)+16; i++)
3255 {
3256 auto data = TheMaps[layerscreen].data[i];
3257 auto cs = TheMaps[layerscreen].cset[i];
3258 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3259 }
3260 }
3261 }
3262 }
3263
3264 if(flags&cWALK)
3265 {
3266 if(LayerMaskInt[0]!=0)
3267 {
3268 for(int32_t i=c; i<(c&0xF0)+16; i++)
3269 {
3270 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3271 }
3272 }
3273
3274 for(int32_t k=0; k<2; k++)
3275 {
3276 if(LayerMaskInt[k+1]!=0)
3277 {
3278 for(int32_t i=c; i<(c&0xF0)+16; i++)
3279 {
3280 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3281 }
3282 }
3283 }
3284 }
3285
3286 if(flags&cFLAGS)
3287 {
3288 if(LayerMaskInt[CurrentLayer]!=0)
3289 {
3290 for(int32_t i=c; i<(c&0xF0)+16; i++)
3291 {
3292 if(CurrentLayer==0)
3293 {
3294 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3295 }
3296 else
3297 {
3298 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3299
3300 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3301 {
3302 if(i < 176)
3303 {
3304 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3305 TheMaps[_lscr].data[i],
3306 TheMaps[_lscr].cset[i], flags|dark,
3307 TheMaps[_lscr].sflag[i]);
3308 }
3309 else
3310 {
3311 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3312 }
3313 }
3314 }
3315 }
3316 }
3317
3318 /*
3319 if (LayerMaskInt[0]!=0) {
3320 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3321 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3322 }
3323 }
3324 */
3325 }
3326
3327 if(ShowMisalignments)
3328 {
3329 if(c<16)
3330 {
3331 check_alignments(dest,x,y,scr);
3332 }
3333 else if(c>159)
3334 {
3335 check_alignments(dest,x,y-160,scr);
3336 }
3337 }
3338 }
3339
3340 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3341 {
3342 if(map<0)
3343 map=cursor.map;
3344
3345 if(scr<0)
3346 scr=cursor.screen;
3347
3348 mapscr* layer=AbsoluteScr(map,scr);
3349 int32_t layermap=0, layerscreen=0;
3350
3351 if(!(layer->valid&mVALID))
3352 {
3353 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3354 rectfill(dest,x,y,x+15,y+175,vc(1));
3355 return;
3356 }
3357
3358 int32_t dark = layer->flags&4;
3359
3360 if(LayerMaskInt[0]==0)
3361 {
3362 rectfill(dest,x,y,x+15,y+175,0);
3363 }
3364
3365
3366 for(int32_t k=1; k<3; k++)
3367 {
3368 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3369 {
3370 layermap=layer->layermap[k]-1;
3371
3372 if(layermap>-1 && layermap<map_count)
3373 {
3374 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3375
3376 for(int32_t i=c; i<176; i+=16)
3377 {
3378 auto data = TheMaps[layerscreen].data[i];
3379 auto cs = TheMaps[layerscreen].cset[i];
3380 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3381 }
3382 }
3383 }
3384 }
3385
3386 if(LayerMaskInt[0]!=0)
3387 {
3388 for(int32_t i=c; i<176; i+=16)
3389 {
3390 word cmbdat = layer->data[i];
3391 byte cmbcset = layer->cset[i];
3392 int32_t cmbflag = layer->sflag[i];
3393 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3394 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3395 }
3396 }
3397
3398 for(int32_t k=0; k<2; k++)
3399 {
3400 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3401 {
3402 layermap=layer->layermap[k]-1;
3403
3404 if(layermap>-1 && layermap<map_count)
3405 {
3406 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3407
3408 for(int32_t i=c; i<176; i+=16)
3409 {
3410 auto data = TheMaps[layerscreen].data[i];
3411 auto cs = TheMaps[layerscreen].cset[i];
3412 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3413 }
3414 }
3415 }
3416 }
3417
3418 int32_t doortype[4];
3419
3420 for(int32_t i=0; i<4; i++)
3421 {
3422 switch(layer->door[i])
3423 {
3424 case dOPEN:
3425 doortype[i]=dt_pass;
3426 break;
3427
3428 case dLOCKED:
3429 doortype[i]=dt_lock;
3430 break;
3431
3432 case d1WAYSHUTTER:
3433 case dSHUTTER:
3434 doortype[i]=dt_shut;
3435 break;
3436
3437 case dBOSS:
3438 doortype[i]=dt_boss;
3439 break;
3440
3441 case dBOMB:
3442 doortype[i]=dt_bomb;
3443 break;
3444 }
3445 }
3446
3447 if((c&0x0F)==0)
3448 {
3449 switch(layer->door[left])
3450 {
3451
3452 case dBOMB:
3453 case dOPEN:
3454 case dLOCKED:
3455 case d1WAYSHUTTER:
3456 case dSHUTTER:
3457 case dBOSS:
3458 // put_door(dest,64,left,doortype[left],x+256,y,true);
3459 put_door(dest,64,left,doortype[left],x,y,true,scr);
3460 break;
3461 }
3462 }
3463 else if((c&0x0F)==15)
3464 {
3465 switch(layer->door[right])
3466 {
3467 case dBOMB:
3468 case dOPEN:
3469 case dLOCKED:
3470 case d1WAYSHUTTER:
3471 case dSHUTTER:
3472 case dBOSS:
3473 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3474 break;
3475 }
3476 }
3477
3478 for(int32_t k=2; k<4; k++)
3479 {
3480 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3481 {
3482 layermap=layer->layermap[k]-1;
3483
3484 if(layermap>-1 && layermap<map_count)
3485 {
3486 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3487
3488 for(int32_t i=c; i<176; i+=16)
3489 {
3490 auto data = TheMaps[layerscreen].data[i];
3491 auto cs = TheMaps[layerscreen].cset[i];
3492 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3493 }
3494 }
3495 }
3496 }
3497
3498 //Overhead L0
3499 if(LayerMaskInt[0]!=0)
3500 {
3501 for(int32_t i=c; i<176; i+=16)
3502 {
3503 auto data = TheMaps[layerscreen].data[i];
3504 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3505 auto cs = TheMaps[layerscreen].cset[i];
3506 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3507 }
3508 }
3509 //Overhead L1/2
3510 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3511 {
3512 for(int32_t k = 0; k < 2; ++k)
3513 {
3514 if(LayerMaskInt[k+1]!=0)
3515 {
3516 layermap=layer->layermap[k]-1;
3517
3518 if(layermap>-1 && layermap<map_count)
3519 {
3520 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3521 for(int32_t i=c; i<176; i+=16)
3522 {
3523 auto data = TheMaps[layerscreen].data[i];
3524 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3525 auto cs = TheMaps[layerscreen].cset[i];
3526 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3527 }
3528 }
3529 }
3530 }
3531 }
3532
3533
3534 for(int32_t k=4; k<6; k++)
3535 {
3536 if(LayerMaskInt[k+1]!=0)
3537 {
3538 layermap=layer->layermap[k]-1;
3539
3540 if(layermap>-1 && layermap<map_count)
3541 {
3542 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3543
3544 for(int32_t i=c; i<176; i+=16)
3545 {
3546 auto data = TheMaps[layerscreen].data[i];
3547 auto cs = TheMaps[layerscreen].cset[i];
3548 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3549 }
3550 }
3551 }
3552 }
3553
3554 if(flags&cWALK)
3555 {
3556 if(LayerMaskInt[0]!=0)
3557 {
3558 for(int32_t i=c&0xF; i<176; i+=16)
3559 {
3560 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3561 }
3562 }
3563
3564 for(int32_t k=0; k<2; k++)
3565 {
3566 if(LayerMaskInt[k+1]!=0)
3567 {
3568 for(int32_t i=c&0xF; i<176; i+=16)
3569 {
3570 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3571 }
3572 }
3573 }
3574 }
3575
3576 if(flags&cFLAGS)
3577 {
3578 if(LayerMaskInt[CurrentLayer]!=0)
3579 {
3580 for(int32_t i=c; i<176; i+=16)
3581 {
3582 if(CurrentLayer==0)
3583 {
3584 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3585 }
3586 else
3587 {
3588 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3589
3590 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3591 {
3592 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3593 TheMaps[_lscr].data[i],
3594 TheMaps[_lscr].cset[i], flags|dark,
3595 TheMaps[_lscr].sflag[i]);
3596 }
3597 }
3598 }
3599 }
3600 }
3601
3602 if(ShowMisalignments)
3603 {
3604 if((c&0x0F)==0)
3605 {
3606 check_alignments(dest,x,y,scr);
3607 }
3608 else if((c&0x0F)==15)
3609 {
3610 check_alignments(dest,x-240,y,scr);
3611 }
3612 }
3613 }
3614
3615 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3616 {
3617 if(map<0)
3618 map=cursor.map;
3619
3620 if(scr<0)
3621 scr=cursor.screen;
3622
3623 mapscr* layer=AbsoluteScr(map,scr);
3624 int32_t layermap=0, layerscreen=0;
3625
3626 if(!(layer->valid&mVALID))
3627 {
3628 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3629 rectfill(dest,x,y,x+15,y+15,vc(1));
3630 return;
3631 }
3632
3633 int32_t dark = layer->flags&4;
3634
3635 if(LayerMaskInt[0]!=0)
3636 {
3637 rectfill(dest,x,y,x+15,y+15,0);
3638 }
3639
3640 for(int32_t k=1; k<3; k++)
3641 {
3642 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3643 {
3644 layermap=layer->layermap[k]-1;
3645
3646 if(layermap>-1 && layermap<map_count)
3647 {
3648 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3649
3650 auto data = TheMaps[layerscreen].data[c];
3651 auto cs = TheMaps[layerscreen].cset[c];
3652 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3653 }
3654 }
3655 }
3656
3657 if(LayerMaskInt[0]!=0)
3658 {
3659 word cmbdat = layer->data[c];
3660 byte cmbcset = layer->cset[c];
3661 int32_t cmbflag = layer->sflag[c];
3662 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3663 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3664 }
3665
3666
3667 for(int32_t k=0; k<2; k++)
3668 {
3669 if(LayerMaskInt[k+1]!=0)
3670 {
3671 layermap=layer->layermap[k]-1;
3672
3673 if(layermap>-1 && layermap<map_count)
3674 {
3675 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3676
3677 auto data = TheMaps[layerscreen].data[c];
3678 auto cs = TheMaps[layerscreen].cset[c];
3679 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3680 }
3681 }
3682 }
3683
3684 for(int32_t k=2; k<4; k++)
3685 {
3686 if(LayerMaskInt[k+1]!=0)
3687 {
3688 layermap=layer->layermap[k]-1;
3689
3690 if(layermap>-1 && layermap<map_count)
3691 {
3692 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3693 auto data = TheMaps[layerscreen].data[c];
3694 auto cs = TheMaps[layerscreen].cset[c];
3695 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3696 }
3697 }
3698 }
3699
3700 //Overhead L0
3701 if(LayerMaskInt[0]!=0)
3702 {
3703 auto data = TheMaps[layerscreen].data[c];
3704 if(combo_class_buf[combobuf[data].type].overhead)
3705 {
3706 auto cs = TheMaps[layerscreen].cset[c];
3707 drawcombo(dest,x,y,data,cs,0,0);
3708 }
3709 }
3710 //Overhead L1/2
3711 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3712 {
3713 for(int32_t k = 0; k < 2; ++k)
3714 {
3715 if(LayerMaskInt[k+1]!=0)
3716 {
3717 layermap=layer->layermap[k]-1;
3718
3719 if(layermap>-1 && layermap<map_count)
3720 {
3721 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3722 auto data = TheMaps[layerscreen].data[c];
3723 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3724 auto cs = TheMaps[layerscreen].cset[c];
3725 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3726 }
3727 }
3728 }
3729 }
3730
3731
3732 for(int32_t k=4; k<6; k++)
3733 {
3734 if(LayerMaskInt[k+1]!=0)
3735 {
3736 layermap=layer->layermap[k]-1;
3737
3738 if(layermap>-1 && layermap<map_count)
3739 {
3740 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3741 auto data = TheMaps[layerscreen].data[c];
3742 auto cs = TheMaps[layerscreen].cset[c];
3743 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3744 }
3745 }
3746 }
3747
3748 if(flags&cWALK)
3749 {
3750 if(LayerMaskInt[0]!=0)
3751 {
3752 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3753 }
3754
3755 for(int32_t k=0; k<2; k++)
3756 {
3757 if(LayerMaskInt[k+1]!=0)
3758 {
3759 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3760 }
3761 }
3762 }
3763
3764 if(flags&cFLAGS)
3765 {
3766 if(LayerMaskInt[CurrentLayer]!=0)
3767 {
3768 int32_t i = c;
3769 //for(int32_t i=c; i==c; i++)
3770 {
3771 if(CurrentLayer==0)
3772 {
3773 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3774 }
3775 else
3776 {
3777 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3778
3779 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3780 {
3781 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3782 TheMaps[_lscr].data[i],
3783 TheMaps[_lscr].cset[i], flags|dark,
3784 TheMaps[_lscr].sflag[i]);
3785 }
3786 }
3787 }
3788 }
3789 }
3790
3791 if(ShowMisalignments)
3792 {
3793 switch(c)
3794 {
3795 case 0:
3796 check_alignments(dest,x,y,scr);
3797 break;
3798
3799 case 15:
3800 check_alignments(dest,x-240,y,scr);
3801 break;
3802
3803 case 160:
3804 check_alignments(dest,x,y-160,scr);
3805 break;
3806
3807 case 175:
3808 check_alignments(dest,x-240,y-160,scr);
3809 break;
3810 }
3811 }
3812 }
3813
3814 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3815 {
3816 if (InvalidBG == 2)
3817 {
3818 draw_checkerboard(dest, x, y, 16);
3819 }
3820 else if(InvalidBG == 1)
3821 {
3822 for(int32_t dy=0; dy<16; dy++)
3823 {
3824 for(int32_t dx=0; dx<16; dx++)
3825 {
3826 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3827 }
3828 }
3829 }
3830 else
3831 {
3832 rectfill(dest, x, y, x+15, y+15, vc(0));
3833 rect(dest, x, y, x+15, y+15, vc(15));
3834 line(dest, x, y, x+15, y+15, vc(15));
3835 line(dest, x, y+15, x+15, y, vc(15));
3836 }
3837 }
3838
3839 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3840 {
3841 if (InvalidBG == 2)
3842 {
3843 for(int32_t q = 0; q < 11; ++q)
3844 draw_checkerboard(dest, x, y + q * 16, 16);
3845 }
3846 else if(InvalidBG == 1)
3847 {
3848 for(int32_t dy=0; dy<176; dy++)
3849 {
3850 for(int32_t dx=0; dx<16; dx++)
3851 {
3852 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3853 }
3854 }
3855 }
3856 else
3857 {
3858 rectfill(dest, x, y, x+15, y+175, vc(0));
3859 rect(dest, x, y, x+15, y+175, vc(15));
3860 line(dest, x, y, x+15, y+175, vc(15));
3861 line(dest, x, y+175, x+15, y, vc(15));
3862 }
3863 }
3864
3865 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3866 {
3867 if (InvalidBG == 2)
3868 {
3869 for (int32_t q = 0; q < 16; ++q)
3870 draw_checkerboard(dest, x + q * 16, y, 16);
3871 }
3872 else if(InvalidBG == 1)
3873 {
3874 for(int32_t dy=0; dy<16; dy++)
3875 {
3876 for(int32_t dx=0; dx<256; dx++)
3877 {
3878 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3879 }
3880 }
3881 }
3882 else
3883 {
3884 rectfill(dest, x, y, x+255, y+15, vc(0));
3885 rect(dest, x, y, x+255, y+15, vc(15));
3886 line(dest, x, y, x+255, y+15, vc(15));
3887 line(dest, x, y+15, x+255, y, vc(15));
3888 }
3889 }
3890
3891 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3892 {
3893 for(int32_t i=0; i<176; i++)
3894 {
3895 word cmbdat = screens[TEMPLATE].data[i];
3896 byte cmbcset = screens[TEMPLATE].cset[i];
3897 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3898 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3899 }
3900 }
3901
3902 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3903 {
3904 for(int32_t i=0; i<176; i++)
3905 {
3906 word cmbdat = screens[TEMPLATE2].data[i];
3907 byte cmbcset = screens[TEMPLATE2].cset[i];
3908 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3909 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3910 }
3911 }
3912
3913 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3914 {
3915 word cmbdat = screens[TEMPLATE].data[pos];
3916 byte cmbcset = screens[TEMPLATE].cset[pos];
3917 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3918 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3919 }
3920
3921 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3922 {
3923 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3924 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3925 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3926 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3927 }
3928
3929 void zmap::scroll(int32_t dir, bool warp)
3930 {
3931 if(cursor.map<map_count)
3932 {
3933 switch(dir)
3934 {
3935 case up:
3936 if(warp && Map.CurrScr()->flags2&wfUP)
3937 {
3938 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3939 }
3940 else if(cursor.screen>15)
3941 {
3942 setCurrScr(cursor.screen - 16);
3943 }
3944
3945 break;
3946
3947 case down:
3948 if(warp && Map.CurrScr()->flags2&wfDOWN)
3949 {
3950 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3951 }
3952 else if(cursor.screen<MAPSCRS-16)
3953 {
3954 setCurrScr(cursor.screen + 16);
3955 }
3956
3957 break;
3958
3959 case left:
3960 if(warp && Map.CurrScr()->flags2&wfLEFT)
3961 {
3962 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3963 }
3964 else if(cursor.screen&15)
3965 {
3966 setCurrScr(cursor.screen - 1);
3967 }
3968
3969 break;
3970
3971 case right:
3972 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3973 {
3974 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3975 }
3976 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3977 {
3978 setCurrScr(cursor.screen + 1);
3979 }
3980
3981 break;
3982 }
3983 }
3984 }
3985
3986 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3987 {
3988 switch(side)
3989 {
3990 case up:
3991 switch(door)
3992 {
3993 case dWALL:
3994 case dBOMB:
3995 case dWALK:
3996 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3997 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3998 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3999 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4000 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4001 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4002 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4003 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4004 break;
4005
4006 default:
4007 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4008 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4009 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4010 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4011 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4012 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4013 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4014 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4015 break;
4016 }
4017
4018 break;
4019
4020 case down:
4021 switch(door)
4022 {
4023 case dWALL:
4024 case dBOMB:
4025 case dWALK:
4026 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4027 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4028 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4029 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4030 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4031 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4032 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4033 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4034 break;
4035
4036 default:
4037 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4038 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4039 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4040 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4041 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4042 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4043 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4044 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4045 break;
4046 }
4047
4048 break;
4049
4050 case left:
4051 switch(door)
4052 {
4053 case dWALL:
4054 case dBOMB:
4055 case dWALK:
4056 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4057 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4058 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4059 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4060 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4061 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4062 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4063 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4064 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4065 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4066 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4067 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4068 break;
4069
4070 default:
4071 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4072 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4073 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4074 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4075 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4076 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4077 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4078 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4079 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4080 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4081 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4082 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4083 break;
4084 }
4085
4086 break;
4087
4088 case right:
4089 switch(door)
4090 {
4091 case dWALL:
4092 case dBOMB:
4093 case dWALK:
4094 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4095 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4096 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4097 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4098 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4099 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4100 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4101 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4102 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4103 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4104 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4105 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4106 break;
4107
4108 default:
4109 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4110 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4111 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4112 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4113 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4114 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4115 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4116 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4117 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4118 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4119 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4120 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4121 break;
4122 }
4123
4124 break;
4125 }
4126 }
4127 void zmap::DoPutDoorCommand(int side, int door, bool force)
4128 {
4129 if(!force && screens[cursor.screen].door[side] == door)
4130 return;
4131 bool already_list = InListCommand();
4132 if(!already_list)
4133 StartListCommand();
4134 DoSetDoorCommand(cursor.screen,side,door);
4135 if(door != dNONE)
4136 {
4137 word data[176] = {0};
4138 byte cset[176] = {0};
4139 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4140 for(int q = 0; q < 176; ++q)
4141 if(data[q])
4142 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4143 }
4144 if(!already_list)
4145 FinishListCommand();
4146 }
4147 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4148 {
4149 if(screens[screen].door[side] == door)
4150 return;
4151
4152 screens[screen].door[side] = door;
4153 if(door != dNONE)
4154 {
4155 word data[176] = {0};
4156 byte cset[176] = {0};
4157 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4158 for(int q = 0; q < 176; ++q)
4159 if(data[q])
4160 {
4161 screens[screen].data[q] = data[q];
4162 screens[screen].cset[q] = cset[q];
4163 }
4164 }
4165 }
4166
4167 void list_command::execute()
4168 {
4169 for (auto command : commands)
4170 {
4171 command->execute();
4172 }
4173 }
4174
4175 void list_command::undo()
4176 {
4177 for (int i = commands.size() - 1; i >= 0; i--)
4178 {
4179 commands[i]->undo();
4180 }
4181 }
4182
4183 int list_command::size()
4184 {
4185 int s = 0;
4186 for (auto command : commands)
4187 {
4188 s += command->size();
4189 }
4190 return s;
4191 }
4192
4193 void set_combo_command::execute()
4194 {
4195 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4196 if (!scr_ptr) return;
4197
4198 if (combo != -1) scr_ptr->data[pos] = combo;
4199 scr_ptr->cset[pos] = cset;
4200 }
4201
4202 void set_combo_command::undo()
4203 {
4204 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4205 if(!mapscr_ptr) return;
4206 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4207 mapscr_ptr->cset[pos] = prev_cset;
4208 }
4209
4210 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4211 {
4212 std::array<int, 8> initd_arr;
4213 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4214
4215 return {
4216 .x = ffc.x,
4217 .y = ffc.y,
4218 .vx = ffc.vx,
4219 .vy = ffc.vy,
4220 .ax = ffc.ax,
4221 .ay = ffc.ay,
4222 .data = ffc.data,
4223 .cset = ffc.cset,
4224 .delay = ffc.delay,
4225 .link = ffc.link,
4226 .script = ffc.script,
4227 .tw = ffc.txsz,
4228 .th = ffc.tysz,
4229 .ew = ffc.hit_width,
4230 .eh = ffc.hit_height,
4231 .flags = ffc.flags,
4232 .initd = initd_arr,
4233 .layer = ffc.layer
4234 };
4235 }
4236
4237 void set_ffc_command::execute()
4238 {
4239 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4240 if(!mapscr_ptr) return;
4241
4242 mapscr_ptr->valid |= mVALID;
4243 mapscr_ptr->ffcs[i].x = data.x;
4244 mapscr_ptr->ffcs[i].y = data.y;
4245 mapscr_ptr->ffcs[i].vx = data.vx;
4246 mapscr_ptr->ffcs[i].vy = data.vy;
4247 mapscr_ptr->ffcs[i].ax = data.ax;
4248 mapscr_ptr->ffcs[i].ay = data.ay;
4249 mapscr_ptr->ffcs[i].data = data.data;
4250 mapscr_ptr->ffcs[i].cset = data.cset;
4251 mapscr_ptr->ffcs[i].delay = data.delay;
4252 mapscr_ptr->ffcs[i].link = data.link;
4253 mapscr_ptr->ffcs[i].script = data.script;
4254 mapscr_ptr->ffcs[i].flags = data.flags;
4255 mapscr_ptr->ffEffectWidth(i, data.ew);
4256 mapscr_ptr->ffEffectHeight(i, data.eh);
4257 mapscr_ptr->ffTileWidth(i, data.tw);
4258 mapscr_ptr->ffTileHeight(i, data.th);
4259 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4260 mapscr_ptr->ffcs[i].layer = data.layer;
4261 mapscr_ptr->ffcCountMarkDirty();
4262 mapscr_ptr->ffcs[i].updateSolid();
4263 }
4264
4265 void set_ffc_command::undo()
4266 {
4267 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4268 if(!mapscr_ptr) return;
4269
4270 mapscr_ptr->ffcs[i].x = prev_data.x;
4271 mapscr_ptr->ffcs[i].y = prev_data.y;
4272 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4273 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4274 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4275 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4276 mapscr_ptr->ffcs[i].data = prev_data.data;
4277 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4278 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4279 mapscr_ptr->ffcs[i].link = prev_data.link;
4280 mapscr_ptr->ffcs[i].script = prev_data.script;
4281 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4282 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4283 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4284 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4285 mapscr_ptr->ffTileHeight(i, prev_data.th);
4286 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4287 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4288 mapscr_ptr->ffcCountMarkDirty();
4289 mapscr_ptr->ffcs[i].updateSolid();
4290 }
4291
4292 void set_flag_command::execute()
4293 {
4294 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4295 if(!mapscr_ptr) return;
4296
4297 mapscr_ptr->valid |= mVALID;
4298 mapscr_ptr->sflag[pos] = flag;
4299 }
4300
4301 void set_flag_command::undo()
4302 {
4303 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4304 if(!mapscr_ptr) return;
4305 mapscr_ptr->sflag[pos] = prev_flag;
4306 }
4307
4308 void set_door_command::execute()
4309 {
4310 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4311 if(!mapscr_ptr) return;
4312
4313 mapscr_ptr->valid |= mVALID;
4314 mapscr_ptr->door[side] = door;
4315 }
4316
4317 void set_door_command::undo()
4318 {
4319 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4320 }
4321
4322 void set_dcs_command::execute()
4323 {
4324 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4325 if(!mapscr_ptr) return;
4326
4327 mapscr_ptr->valid |= mVALID;
4328 mapscr_ptr->door_combo_set = dcs;
4329 }
4330
4331 void set_dcs_command::undo()
4332 {
4333 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4334 }
4335
4336 void paste_screen_command::execute()
4337 {
4338 perform(screen.get());
4339 }
4340
4341 void paste_screen_command::undo()
4342 {
4343 if (prev_screens.size() > 1)
4344 {
4345 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4346 ASSERT(prev_screens.size() == 128);
4347 for (int i = 0; i < 128; i++)
4348 {
4349 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4350 // TODO: why not just this?
4351 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4352 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4353 }
4354 return;
4355 }
4356
4357 perform(prev_screens[0].get());
4358 }
4359
4360 int paste_screen_command::size()
4361 {
4362 return prev_screens.size() + 1;
4363 }
4364
4365 void paste_screen_command::perform(mapscr* to)
4366 {
4367 if (to)
4368 {
4369 switch (type) {
4370 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4371 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4372 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4373 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4374 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4375 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4376 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4377 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4378 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4379 case ScreenPartial: Map.Paste(*to, screen_index); break;
4380 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4381 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4382 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4383 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4384 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4385 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4386 }
4387 }
4388 else
4389 {
4390 Map.clearscr(screen_index);
4391 }
4392 refresh(rALL);
4393 }
4394
4395 void set_screen_command::execute()
4396 {
4397 if (screen)
4398 {
4399 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4400 }
4401 else
4402 {
4403 Map.clearscr(screen_index);
4404 }
4405 refresh(rALL);
4406 }
4407
4408 void set_screen_command::undo()
4409 {
4410 if (prev_screen)
4411 {
4412 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4413 }
4414 else
4415 {
4416 Map.clearscr(screen_index);
4417 }
4418 refresh(rALL);
4419 }
4420
4421 int set_screen_command::size()
4422 {
4423 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4424 }
4425
4426 static std::shared_ptr<list_command> current_list_command;
4427 void zmap::StartListCommand()
4428 {
4429 ASSERT(!current_list_command);
4430 current_list_command.reset(new list_command);
4431 }
4432
4433 void zmap::FinishListCommand()
4434 {
4435 if (current_list_command->commands.size() == 1)
4436 {
4437 undo_stack.push_back(current_list_command->commands[0]);
4438 }
4439 else if (current_list_command->commands.size() > 1)
4440 {
4441 undo_stack.push_back(current_list_command);
4442 }
4443 CapCommandHistory();
4444 current_list_command = nullptr;
4445 }
4446
4447 void zmap::RevokeListCommand()
4448 {
4449 current_list_command->undo();
4450 current_list_command = nullptr;
4451 }
4452
4453 bool zmap::InListCommand() const
4454 {
4455 return current_list_command ? true : false;
4456 }
4457
4458 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4459 {
4460 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4461 if (!skip_execute) command->execute();
4462 if (current_list_command)
4463 {
4464 current_list_command->commands.push_back(command);
4465 if (current_list_command->commands.size() == 1)
4466 {
4467 current_list_command->cursor = command->cursor;
4468 }
4469 }
4470 else
4471 {
4472 undo_stack.push_back(command);
4473 CapCommandHistory();
4474 }
4475 saved = false;
4476 }
4477
4478 void zmap::UndoCommand()
4479 {
4480 if (undo_stack.size() <= 0) return;
4481
4482 // If not currently looking at the associated screen, first change the view
4483 // and wait for the next call to actually undo this command.
4484 auto command = undo_stack.back();
4485 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4486 {
4487 setCursor(command.get()->cursor);
4488 return;
4489 }
4490
4491 command->undo();
4492 redo_stack.push(command);
4493 undo_stack.pop_back();
4494 saved = false;
4495 }
4496
4497 void zmap::RedoCommand()
4498 {
4499 if (redo_stack.size() <= 0) return;
4500
4501 // If not currently selected the associated screen, first change the cursor
4502 // and wait for the next call to actually execute this command.
4503 auto command = redo_stack.top();
4504 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4505 {
4506 setCursor(command.get()->cursor);
4507 return;
4508 }
4509
4510 command->execute();
4511 undo_stack.push_back(command);
4512 redo_stack.pop();
4513 saved = false;
4514 }
4515
4516 11 void zmap::ClearCommandHistory()
4517 {
4518 11 current_list_command = nullptr;
4519 11 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4520 11 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4521 11 }
4522
4523 // Extra amount is from mapscr's vectors.
4524 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4525 // Allow the undo system to use roughly 100 MB of memory.
4526 // This doesn't count the memory used by commands that don't store a mapscr,
4527 // but that should be negligible.
4528 12 static int max_command_size = 100e6 / size_of_mapscr;
4529 void zmap::CapCommandHistory()
4530 {
4531 int size;
4532 do
4533 {
4534 size = 0;
4535 for (auto command : undo_stack)
4536 {
4537 size += command->size();
4538 }
4539 if (size > max_command_size) undo_stack.pop_front();
4540 } while (size > max_command_size);
4541 }
4542
4543 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4544 {
4545 if (!pos.is_valid(cursor))
4546 return;
4547
4548 int map = cursor.map;
4549 int screen = cursor.viewscr + pos.screen_offset();
4550 if (!AbsoluteScr(map, screen))
4551 return;
4552
4553 if (CurrentLayer)
4554 {
4555 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4556 map = scr->layermap[CurrentLayer-1]-1;
4557 screen = scr->layerscreen[CurrentLayer-1];
4558 }
4559 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4560 }
4561
4562 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4563 {
4564 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4565 if (!mapscr_ptr) return;
4566
4567 std::shared_ptr<set_combo_command> command(new set_combo_command);
4568 command->cursor = cursor;
4569 command->map = map;
4570 command->scr = scr;
4571 command->pos = pos;
4572 command->combo = combo;
4573 command->cset = cset;
4574 command->prev_combo = mapscr_ptr->data[pos];
4575 command->prev_cset = mapscr_ptr->cset[pos];
4576 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4577 {
4578 // nothing to do...
4579 return;
4580 }
4581
4582 ExecuteCommand(command);
4583 }
4584
4585 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4586 {
4587 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4588 if(!mapscr_ptr) return;
4589
4590 mapscr_ptr->ensureFFC(i);
4591
4592 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4593
4594 std::array<int, 8> initd_arr;
4595 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4596
4597 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4598
4599 command->cursor = cursor;
4600 command->map = map;
4601 command->scr = scr;
4602 command->i = i;
4603 command->data = data;
4604 command->prev_data = prev_data;
4605 if (data == prev_data)
4606 {
4607 // nothing to do...
4608 return;
4609 }
4610
4611 ExecuteCommand(command);
4612 }
4613
4614 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4615 {
4616 if (!pos.is_valid(cursor))
4617 return;
4618
4619 int map = cursor.map;
4620 int screen = cursor.viewscr + pos.screen_offset();
4621 if (!AbsoluteScr(map, screen))
4622 return;
4623
4624 if (CurrentLayer)
4625 {
4626 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4627 map = scr->layermap[CurrentLayer-1]-1;
4628 screen = scr->layerscreen[CurrentLayer-1];
4629 }
4630 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4631 }
4632
4633 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4634 {
4635 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4636 if(!mapscr_ptr) return;
4637
4638 std::shared_ptr<set_flag_command> command(new set_flag_command);
4639 command->cursor = cursor;
4640 command->map = map;
4641 command->scr = scr;
4642 command->pos = pos;
4643 command->flag = flag;
4644 command->prev_flag = mapscr_ptr->sflag[pos];
4645 if (command->flag == command->prev_flag)
4646 {
4647 // nothing to do...
4648 return;
4649 }
4650
4651 ExecuteCommand(command);
4652 }
4653
4654 void zmap::DoSetDoorCommand(int scr, int side, int door)
4655 {
4656 if(screens[scr].door[side] == door)
4657 return;
4658 std::shared_ptr<set_door_command> command(new set_door_command);
4659 command->cursor = cursor;
4660 command->side = side;
4661 command->door = door;
4662 command->prev_door = screens[scr].door[side];
4663
4664 ExecuteCommand(command);
4665 }
4666 void zmap::DoSetDCSCommand(int dcs)
4667 {
4668 if(screens[cursor.screen].door_combo_set == dcs)
4669 return;
4670 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4671 command->cursor = cursor;
4672 command->dcs = dcs;
4673 command->prev_dcs = screens[cursor.screen].door_combo_set;
4674
4675 ExecuteCommand(command);
4676 }
4677
4678 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4679 {
4680 if (screen == -1)
4681 screen = cursor.screen;
4682
4683 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4684 command->cursor = cursor;
4685 command->type = type;
4686 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4687 command->screen_index = screen;
4688
4689 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4690 {
4691 for (int i=0; i < 128; i++)
4692 {
4693 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4694 }
4695 }
4696 else
4697 {
4698 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4699 }
4700
4701 ExecuteCommand(command);
4702 }
4703
4704 void zmap::DoClearScreenCommand(int screen)
4705 {
4706 std::shared_ptr<set_screen_command> command(new set_screen_command);
4707 command->cursor = cursor;
4708 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4709 command->screen = std::shared_ptr<mapscr>(nullptr);
4710 command->screen_index = screen;
4711
4712 ExecuteCommand(command);
4713 }
4714
4715 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4716 {
4717 std::shared_ptr<set_screen_command> command(new set_screen_command);
4718 command->cursor = cursor;
4719 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4720 Template(floorcombo, floorcset, screen);
4721 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4722
4723 ExecuteCommand(command, true);
4724 }
4725
4726 void zmap::Copy(int scr)
4727 {
4728 if(screens[scr].valid&mVALID)
4729 {
4730 copy_mapscr(&copymapscr, &screens[scr]);
4731 //copymapscr=screens[scr];
4732 can_paste=true;
4733 copymap=cursor.map;
4734 copyscr=scr;
4735 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4736 copyffc = -1;
4737 }
4738 }
4739
4740 void zmap::CopyFFC(int32_t screen, int32_t n)
4741 {
4742 if(screens[screen].valid&mVALID)
4743 {
4744 copy_mapscr(&copymapscr, &screens[screen]);
4745 // Can't paste the screen itself
4746 can_paste = false;
4747 copymap=cursor.map;
4748 copyscr=screen;
4749 copyffc = n;
4750 }
4751 }
4752
4753 void zmap::Paste(const mapscr& copymapscr, int screen)
4754 {
4755 if(can_paste)
4756 {
4757 if(!(screens[screen].valid&mVALID))
4758 {
4759 screens[screen].valid |= mVALID;
4760 screens[screen].color = copymapscr.color;
4761 }
4762
4763 screens[screen].door_combo_set = copymapscr.door_combo_set;
4764
4765 for(int32_t i=0; i<4; i++)
4766 {
4767 screens[screen].door[i]=copymapscr.door[i];
4768 }
4769
4770 for(int32_t i=0; i<176; i++)
4771 {
4772 screens[screen].data[i] = copymapscr.data[i];
4773 screens[screen].cset[i] = copymapscr.cset[i];
4774 screens[screen].sflag[i] = copymapscr.sflag[i];
4775 }
4776
4777 refresh_color();
4778
4779 saved=false;
4780 }
4781 }
4782
4783 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4784 {
4785 if(can_paste)
4786 {
4787 screens[screen].undercombo = copymapscr.undercombo;
4788 screens[screen].undercset = copymapscr.undercset;
4789 saved=false;
4790 }
4791 }
4792
4793 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4794 {
4795 if(can_paste)
4796 {
4797 for(int32_t i=0; i<128; i++)
4798 {
4799 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4800 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4801 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4802 }
4803
4804 saved=false;
4805 }
4806 }
4807
4808 // TODO const mapscr& copymapscr
4809 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4810 {
4811 if(can_paste)
4812 {
4813 screens[screen].ffcs = copymapscr.ffcs;
4814 screens[screen].ffcCountMarkDirty();
4815 saved=false;
4816 }
4817 }
4818
4819 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4820 {
4821 if(can_paste)
4822 {
4823 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4824
4825 for(int32_t i=0; i<4; i++)
4826 {
4827 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4828 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4829 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4830 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4831 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4832 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4833 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4834 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4835 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4836 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4837 }
4838
4839 saved=false;
4840 }
4841 }
4842
4843 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4844 {
4845 if(can_paste)
4846 {
4847 screens[screen].csensitive = copymapscr.csensitive;
4848 screens[screen].oceansfx = copymapscr.oceansfx;
4849 screens[screen].bosssfx = copymapscr.bosssfx;
4850 screens[screen].secretsfx = copymapscr.secretsfx;
4851 screens[screen].holdupsfx = copymapscr.holdupsfx;
4852 screens[screen].flags = copymapscr.flags;
4853 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4854 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4855 screens[screen].flags3 = copymapscr.flags3;
4856 screens[screen].flags4 = copymapscr.flags4;
4857 screens[screen].flags5 = copymapscr.flags5;
4858 screens[screen].flags6 = copymapscr.flags6;
4859 screens[screen].flags7 = copymapscr.flags7;
4860 screens[screen].flags8 = copymapscr.flags8;
4861 screens[screen].flags9 = copymapscr.flags9;
4862 screens[screen].flags10 = copymapscr.flags10;
4863 screens[screen].flags11 = copymapscr.flags11;
4864 screens[screen].item = copymapscr.item;
4865 screens[screen].hasitem = copymapscr.hasitem;
4866 screens[screen].itemx = copymapscr.itemx;
4867 screens[screen].itemy = copymapscr.itemy;
4868 screens[screen].nextmap = copymapscr.nextmap;
4869 screens[screen].nextscr = copymapscr.nextscr;
4870 screens[screen].nocarry = copymapscr.nocarry;
4871 screens[screen].noreset = copymapscr.noreset;
4872 screens[screen].exstate_reset = copymapscr.exstate_reset;
4873 screens[screen].exstate_carry = copymapscr.exstate_carry;
4874 screens[screen].path[0] = copymapscr.path[0];
4875 screens[screen].path[1] = copymapscr.path[1];
4876 screens[screen].path[2] = copymapscr.path[2];
4877 screens[screen].path[3] = copymapscr.path[3];
4878 screens[screen].pattern = copymapscr.pattern;
4879 screens[screen].exitdir = copymapscr.exitdir;
4880 screens[screen].screen_midi = copymapscr.screen_midi;
4881 screens[screen].stairx = copymapscr.stairx;
4882 screens[screen].stairy = copymapscr.stairy;
4883 screens[screen].timedwarptics = copymapscr.timedwarptics;
4884 saved=false;
4885 }
4886 }
4887
4888 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4889 {
4890 if(can_paste)
4891 {
4892 screens[screen].warpreturnc = copymapscr.warpreturnc;
4893 screens[screen].warparrivalx = copymapscr.warparrivalx;
4894 screens[screen].warparrivaly = copymapscr.warparrivaly;
4895
4896 for(int32_t i=0; i<4; i++)
4897 {
4898 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4899 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4900 }
4901
4902 saved=false;
4903 }
4904 }
4905
4906 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4907 {
4908 if(can_paste)
4909 {
4910 for(int32_t i=0; i<4; i++)
4911 screens[screen].door[i] = copymapscr.door[i];
4912
4913 screens[screen].door_combo_set = copymapscr.door_combo_set;
4914 saved=false;
4915 }
4916 }
4917
4918 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4919 {
4920 if(can_paste)
4921 {
4922 for(int32_t i=0; i<6; i++)
4923 {
4924 screens[screen].layermap[i] = copymapscr.layermap[i];
4925 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4926 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4927 }
4928
4929 saved=false;
4930 }
4931 }
4932
4933 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4934 {
4935 if(can_paste)
4936 {
4937 screens[screen].room = copymapscr.room;
4938 screens[screen].catchall = copymapscr.catchall;
4939 saved=false;
4940 }
4941 }
4942
4943 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4944 {
4945 if(can_paste)
4946 {
4947 screens[screen].guy = copymapscr.guy;
4948 screens[screen].guytile = copymapscr.guytile;
4949 screens[screen].guycs = copymapscr.guycs;
4950 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4951 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4952 screens[screen].str = copymapscr.str;
4953 saved=false;
4954 }
4955 }
4956
4957 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4958 {
4959 if(can_paste)
4960 {
4961 screens[screen].color = copymapscr.color;
4962 screens[screen].valid|=mVALID;
4963 refresh_color();
4964
4965 saved=false;
4966 }
4967 }
4968
4969 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4970 {
4971 if(can_paste)
4972 {
4973 copy_mapscr(&screens[screen], &copymapscr);
4974 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4975 screens[screen].valid|=mVALID;
4976
4977 refresh_color();
4978
4979 saved=false;
4980 }
4981 }
4982
4983
4984 void zmap::PasteToAll(const mapscr& copymapscr)
4985 {
4986 if(can_paste)
4987 {
4988 for(int32_t x=0; x<128; x++)
4989 {
4990 if(!(screens[x].valid&mVALID))
4991 {
4992 screens[x].valid |= mVALID;
4993 screens[x].color = copymapscr.color;
4994 }
4995
4996 for(int32_t i=0; i<176; i++)
4997 {
4998 screens[x].data[i] = copymapscr.data[i];
4999 screens[x].cset[i] = copymapscr.cset[i];
5000 screens[x].sflag[i] = copymapscr.sflag[i];
5001 }
5002 }
5003
5004 refresh_color();
5005
5006 saved=false;
5007 }
5008 }
5009
5010 void zmap::PasteAllToAll(const mapscr& copymapscr)
5011 {
5012 if(can_paste)
5013 {
5014 for(int32_t x=0; x<128; x++)
5015 {
5016 copy_mapscr(&screens[x], &copymapscr);
5017 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5018 //screens[x]=copymapscr;
5019 }
5020
5021 refresh_color();
5022
5023 saved=false;
5024 }
5025 }
5026
5027 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5028 {
5029 if(can_paste)
5030 {
5031 for(int32_t i=0; i<10; i++)
5032 screens[screen].enemy[i]=copymapscr.enemy[i];
5033 }
5034 }
5035
5036 void zmap::setCopyFFC(int32_t n)
5037 {
5038 copyffc = n;
5039 }
5040
5041 void zmap::update_combo_cycling()
5042 {
5043 if(!prv_mode||!prv_cmbcycle)
5044 {
5045 return;
5046 }
5047
5048 int32_t x;
5049 int32_t newdata[176];
5050 int32_t newcset[176];
5051 bool restartanim[MAXCOMBOS] = {0};
5052
5053 for(int32_t i=0; i<176; i++)
5054 {
5055 newdata[i]=-1;
5056 newcset[i]=-1;
5057
5058 x=prvscr.data[i];
5059
5060 //time to restart
5061 if((combobuf[x].aclk>=combobuf[x].speed) &&
5062 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5063 combobuf[x].can_cycle())
5064 {
5065 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5066 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5067
5068 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5069 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5070 int32_t c = newdata[i];
5071
5072 if(combobuf[c].animflags & AF_CYCLE)
5073 {
5074 restartanim[c]=true;
5075 }
5076 }
5077 }
5078
5079 for(int32_t i=0; i<176; i++)
5080 {
5081 x=prvscr.data[i];
5082
5083 //time to restart
5084 if((combobuf[x].aclk>=combobuf[x].speed) &&
5085 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5086 combobuf[x].can_cycle())
5087 {
5088 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5089 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5090
5091 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5092 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5093 int32_t c = newdata[i];
5094
5095 if(combobuf[c].animflags & AF_CYCLE)
5096 {
5097 restartanim[c]=true;
5098 }
5099 }
5100 }
5101
5102 for(int32_t i=0; i<176; i++)
5103 {
5104 if(newdata[i]==-1)
5105 continue;
5106
5107 prvscr.data[i]=newdata[i];
5108 prvscr.cset[i]=newcset[i];
5109 }
5110
5111 word maxffc = prvscr.numFFC();
5112 for(word i=0; i<maxffc; i++)
5113 {
5114 ffcdata& ffc = prvscr.ffcs[i];
5115 newcombo const& cmb = combobuf[ffc.data];
5116
5117 //time to restart
5118 if((cmb.aclk>=cmb.speed) &&
5119 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5120 cmb.can_cycle())
5121 {
5122 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5123 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5124
5125 if(!(cmb.animflags & AF_CYCLENOCSET))
5126 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5127
5128 if(combobuf[ffc.data].animflags & AF_CYCLE)
5129 {
5130 restartanim[ffc.data]=true;
5131 }
5132 prvscr.ffcs[i].data = ffc.data;
5133 prvscr.ffcs[i].cset=ffc.cset;
5134 }
5135 }
5136
5137
5138 if(get_qr(qr_CMBCYCLELAYERS))
5139 {
5140 for(int32_t j=0; j<6; j++)
5141 {
5142 if(!prvlayers[j].valid)
5143 continue;
5144
5145 for(int32_t i=0; i<176; i++)
5146 {
5147 newdata[i]=-1;
5148 newcset[i]=-1;
5149
5150 x=(prvlayers[j]).data[i];
5151
5152 //time to restart
5153 if((combobuf[x].aclk>=combobuf[x].speed) &&
5154 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5155 combobuf[x].can_cycle())
5156 {
5157 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5158 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5159
5160 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5161 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5162 int32_t c = newdata[i];
5163
5164 if(combobuf[c].animflags & AF_CYCLE)
5165 {
5166 restartanim[c]=true;
5167 }
5168 }
5169 }
5170
5171 for(int32_t i=0; i<176; i++)
5172 {
5173 x=(prvlayers[j]).data[i];
5174
5175 //time to restart
5176 if((combobuf[x].aclk>=combobuf[x].speed) &&
5177 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5178 combobuf[x].can_cycle())
5179 {
5180 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5181 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5182
5183 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5184 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5185 int32_t c = newdata[i];
5186
5187 if(combobuf[c].animflags & AF_CYCLE)
5188 {
5189 restartanim[c]=true;
5190 }
5191 }
5192 }
5193
5194 for(int32_t i=0; i<176; i++)
5195 {
5196 if(newdata[i]==-1)
5197 continue;
5198
5199 prvlayers[j].data[i]=newdata[i];
5200 prvlayers[j].cset[i]=newcset[i];
5201 }
5202 }
5203 }
5204
5205 for(int32_t i=0; i<MAXCOMBOS; i++)
5206 {
5207 if(restartanim[i])
5208 {
5209 combobuf[i].tile = combobuf[i].o_tile;
5210 combobuf[i].cur_frame=0;
5211 combobuf[i].aclk = 0;
5212 }
5213 }
5214 }
5215
5216 void zmap::update_freeform_combos()
5217 {
5218 if(!prv_mode||!prv_cmbcycle)
5219 {
5220 return;
5221 }
5222
5223 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5224 word maxffc = prvscr.numFFC();
5225 for(int32_t i=0; i<maxffc; i++)
5226 {
5227 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5228 {
5229 for(int32_t j=0; j<maxffc; j++)
5230 {
5231 if(i!=j)
5232 {
5233 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5234 {
5235 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5236 {
5237 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5238 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5239 {
5240 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5241 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5242 if(prvscr.ffcs[j].flags&ffc_changethis)
5243 {
5244 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5245 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5246 }
5247
5248 if(prvscr.ffcs[j].flags&ffc_changenext)
5249 prvscr.ffcs[i].data += 1;
5250
5251 if(prvscr.ffcs[j].flags&ffc_changeprev)
5252 prvscr.ffcs[i].data -= 1;
5253
5254 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5255 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5256 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5257
5258 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5259 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5260 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5261 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5262
5263 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5264 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5265 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5266 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5267 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5268
5269 if(prvscr.ffcs[i].flags&ffc_carryover)
5270 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5271 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5272
5273 prvscr.ffcs[i].flags&=~ffc_changer;
5274 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5275 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5276
5277 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5278 {
5279 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5280 }
5281
5282 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5283 {
5284 int32_t k=0;
5285
5286 if(prvscr.ffcs[j].flags&ffc_swapnext)
5287 k=j<(MAXFFCS-1)?j+1:0;
5288
5289 if(prvscr.ffcs[j].flags&ffc_swapprev)
5290 k=j>0?j-1:(MAXFFCS-1);
5291
5292 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5293 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5294 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5295 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5296 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5297 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5298 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5299 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5300 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5301 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5302 }
5303 }
5304 }
5305 }
5306 }
5307 }
5308
5309 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5310 {
5311 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5312 {
5313 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5314 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5315 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5316 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5317 }
5318 else
5319 {
5320 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5321 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5322 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5323 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5324 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5325 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5326
5327 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5328 {
5329 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5330
5331 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5332
5333 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5334
5335 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5336 }
5337 }
5338 }
5339 else
5340 {
5341 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5342 prvscr.ffcs[i].delay--;
5343 }
5344
5345 if(prvscr.ffcs[i].x<-32)
5346 {
5347 if(prvscr.flags6&fWRAPAROUNDFF)
5348 {
5349 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5350 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5351 }
5352 else
5353 {
5354 prvscr.ffcs[i].data = 0;
5355 prvscr.ffcs[i].flags&=~ffc_carryover;
5356 }
5357 }
5358
5359 if(prvscr.ffcs[i].y<-32)
5360 {
5361 if(prvscr.flags6&fWRAPAROUNDFF)
5362 {
5363 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5364 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5365 }
5366 else
5367 {
5368 prvscr.ffcs[i].data = 0;
5369 prvscr.ffcs[i].flags&=~ffc_carryover;
5370 }
5371 }
5372
5373 if(prvscr.ffcs[i].x>=288)
5374 {
5375 if(prvscr.flags6&fWRAPAROUNDFF)
5376 {
5377 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5378 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5379 }
5380 else
5381 {
5382 prvscr.ffcs[i].data = 0;
5383 prvscr.ffcs[i].flags&=~ffc_carryover;
5384 }
5385 }
5386
5387 if(prvscr.ffcs[i].y>=208)
5388 {
5389 if(prvscr.flags6&fWRAPAROUNDFF)
5390 {
5391 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5392 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5393 }
5394 else
5395 {
5396 prvscr.ffcs[i].data = 0;
5397 prvscr.ffcs[i].flags&=~ffc_carryover;
5398 }
5399 }
5400
5401 }
5402 }
5403 }
5404
5405 void zmap::goto_dmapscr(int dmap, int scr)
5406 {
5407 setCurrMap(DMaps[dmap].map);
5408 setCurrScr(scr+DMaps[dmap].xoff);
5409 }
5410 void zmap::goto_mapscr(int map, int scr)
5411 {
5412 setCurrMap(map);
5413 setCurrScr(scr);
5414 }
5415
5416 void zmap::dowarp(int32_t type, int32_t index)
5417 {
5418 set_warpback();
5419 if(type==0)
5420 {
5421
5422 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5423 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5424
5425 switch(screens[cursor.screen].tilewarptype[index])
5426 {
5427 case wtCAVE:
5428 case wtNOWARP:
5429 break;
5430
5431 default:
5432 goto_dmapscr(dmap, scr);
5433 break;
5434 }
5435 }
5436 else if(type==1)
5437 {
5438 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5439 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5440
5441 switch(screens[cursor.screen].sidewarptype[index])
5442 {
5443 case wtCAVE:
5444 case wtNOWARP:
5445 break;
5446
5447 default:
5448 goto_dmapscr(dmap, scr);
5449 break;
5450 }
5451 }
5452 }
5453
5454 extern int32_t prv_twon;
5455
5456 void zmap::prv_dowarp(int32_t type, int32_t index)
5457 {
5458 if(type==0)
5459 {
5460
5461 int32_t dmap=prvscr.tilewarpdmap[index];
5462 int32_t scr=prvscr.tilewarpscr[index];
5463
5464 switch(prvscr.tilewarptype[index])
5465 {
5466 case wtCAVE:
5467 case wtNOWARP:
5468 break;
5469
5470 default:
5471 //setCurrMap(DMaps[dmap].map);
5472 //setCurrScr(scr+DMaps[dmap].xoff);
5473 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5474 refresh_color();
5475 //prv_cmbcycle=0;
5476 break;
5477 }
5478 }
5479 else if(type==1)
5480 {
5481 int32_t dmap=prvscr.sidewarpdmap[index];
5482 int32_t scr=prvscr.sidewarpscr[index];
5483
5484 switch(prvscr.sidewarptype[index])
5485 {
5486 case wtCAVE:
5487 case wtNOWARP:
5488 break;
5489
5490 default:
5491 //setCurrMap(DMaps[dmap].map);
5492 //setCurrScr(scr+DMaps[dmap].xoff);
5493 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5494 refresh_color();
5495 //prv_cmbcycle=0;
5496 break;
5497 }
5498 }
5499
5500 if(prv_twon)
5501 {
5502 prv_time=get_prvscr()->timedwarptics;
5503 }
5504 }
5505
5506 void zmap::dowarp2(int32_t ring,int32_t index)
5507 {
5508 set_warpback();
5509 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5510 }
5511
5512 void zmap::set_warpback()
5513 {
5514 warpbackmap = cursor.map;
5515 warpbackscreen = cursor.screen;
5516 }
5517 bool zmap::has_warpback()
5518 {
5519 return warpbackmap && warpbackscreen
5520 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5521 }
5522 void zmap::warpback()
5523 {
5524 if(!has_warpback())
5525 return;
5526
5527 int m = cursor.map, s = cursor.screen;
5528 goto_mapscr(*warpbackmap, *warpbackscreen);
5529 warpbackmap = m;
5530 warpbackscreen = s;
5531 }
5532
5533 bool save_msgstrs(const char *path)
5534 {
5535 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5536
5537 if(!f)
5538 {
5539 return false;
5540 }
5541
5542 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5543 {
5544 pack_fclose(f);
5545 return true;
5546 }
5547
5548 pack_fclose(f);
5549 return false;
5550 }
5551
5552 1 bool save_strings_tsv(const char *path)
5553 {
5554 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5555
5556
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5557 {
5558 return false;
5559 }
5560
5561
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5562 {
5563 1 pack_fclose(f);
5564 1 return true;
5565 }
5566
5567 pack_fclose(f);
5568 return false;
5569 1 }
5570
5571 bool save_msgstrs_text(const char *path)
5572 {
5573 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5574
5575 if(!f)
5576 {
5577 return false;
5578 }
5579
5580 if(writestrings_text(f)==0)
5581 {
5582 pack_fclose(f);
5583 return true;
5584 }
5585
5586 pack_fclose(f);
5587 return false;
5588 }
5589
5590 bool load_msgstrs(const char *path, int32_t startstring)
5591 {
5592 //these are here to bypass compiler warnings about unused arguments
5593 startstring=startstring;
5594
5595 dword section_id;
5596 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5597
5598 if(!f)
5599 {
5600 return false;
5601 }
5602
5603 if(!p_mgetl(&section_id,f))
5604 {
5605 return false;
5606 }
5607
5608 if(section_id==ID_STRINGS)
5609 {
5610 if(readstrings(f, &header)==0)
5611 {
5612 pack_fclose(f);
5613 return true;
5614 }
5615 else
5616 {
5617 pack_fclose(f);
5618 return false;
5619 }
5620 }
5621
5622 pack_fclose(f);
5623 return false;
5624 }
5625
5626 bool load_strings_tsv(const char *path)
5627 {
5628 try
5629 {
5630 parse_strings_tsv(util::read_text_file(path));
5631 }
5632 catch (std::exception& ex)
5633 {
5634 InfoDialog("Import .tsv Error", ex.what()).show();
5635 return false;
5636 }
5637 return true;
5638 }
5639
5640 bool save_pals(const char *path)
5641 {
5642 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5643
5644 if(!f)
5645 {
5646 return false;
5647 }
5648
5649 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5650 {
5651 pack_fclose(f);
5652 return true;
5653 }
5654
5655 pack_fclose(f);
5656 return false;
5657 }
5658
5659 bool load_pals(const char *path, int32_t startcset)
5660 {
5661 dword section_id;
5662 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5663
5664 if(!f)
5665 {
5666 return false;
5667 }
5668
5669 if(!p_mgetl(&section_id,f))
5670 {
5671 return false;
5672 }
5673
5674 if(section_id==ID_CSETS)
5675 {
5676 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5677 {
5678 pack_fclose(f);
5679 loadlvlpal(Color);
5680 return true;
5681 }
5682 else
5683 {
5684 pack_fclose(f);
5685 return false;
5686 }
5687 }
5688
5689 return false;
5690 }
5691
5692 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5693 bool save_guys(const char *path)
5694 {
5695 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5696
5697 if(!f)
5698 {
5699 return false;
5700 }
5701
5702 /*
5703 int32_t id = ID_GUYS;
5704 if(!p_mputl(id,f))
5705 {
5706 return false;
5707 }
5708 */
5709
5710 zquestheader h;
5711 h.zelda_version = 0x250;
5712 h.build = 21;
5713
5714 if(writeguys(f, &h)==0)
5715 {
5716 pack_fclose(f);
5717 return true;
5718 }
5719
5720 pack_fclose(f);
5721 return false;
5722 }
5723
5724 bool load_guys(const char *path)
5725 {
5726 dword section_id;
5727 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5728
5729 if(!f)
5730 {
5731 return false;
5732 }
5733
5734 if(!p_mgetl(&section_id,f))
5735 {
5736 pack_fclose(f);
5737 return false;
5738 }
5739
5740 zquestheader h;
5741 h.zelda_version = 0x250;
5742 h.build = 21;
5743
5744 if(section_id==ID_GUYS)
5745 {
5746 if(readguys(f, &h)==0)
5747 {
5748 pack_fclose(f);
5749 return true;
5750 }
5751 }
5752
5753 pack_fclose(f);
5754 return false;
5755 }
5756
5757
5758 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5759 bool save_combo_alias(const char *path)
5760 {
5761 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5762
5763 if(!f)
5764 {
5765 return false;
5766 }
5767
5768 zquestheader h;
5769 h.zelda_version = 0x250;
5770 h.build = 21;
5771
5772 if(writecomboaliases(f, 0, 0)==0)
5773 {
5774 pack_fclose(f);
5775 return true;
5776 }
5777
5778 pack_fclose(f);
5779 return false;
5780 }
5781
5782 bool load_combo_alias(const char *path)
5783 {
5784 dword section_id;
5785 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5786
5787 if(!f)
5788 {
5789 return false;
5790 }
5791
5792 if(!p_mgetl(&section_id,f))
5793 {
5794 pack_fclose(f);
5795 return false;
5796 }
5797
5798 zquestheader h;
5799 h.zelda_version = 0x250;
5800 h.build = 21;
5801
5802 if(section_id==ID_COMBOALIASES)
5803 {
5804 if(readcomboaliases(f, &h, 0, 0)==0)
5805 {
5806 pack_fclose(f);
5807 return true;
5808 }
5809 }
5810
5811 pack_fclose(f);
5812 return false;
5813 }
5814
5815 bool load_zgp(const char *path)
5816 {
5817 dword section_id;
5818 word section_version;
5819 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5820
5821 if(!f)
5822 return false;
5823
5824 if(!p_mgetl(&section_id,f))
5825 {
5826 pack_fclose(f);
5827 return false;
5828 }
5829
5830 if(section_id!=ID_GRAPHICSPACK)
5831 {
5832 pack_fclose(f);
5833 return false;
5834 }
5835
5836 //section version info
5837 if(!p_igetw(&section_version,f))
5838 {
5839 return 2;
5840 }
5841
5842 if(!read_deprecated_section_cversion(f))
5843 {
5844 return 3;
5845 }
5846
5847 //tiles
5848 if(!p_mgetl(&section_id,f))
5849 {
5850 pack_fclose(f);
5851 return false;
5852 }
5853
5854 if(section_id==ID_TILES)
5855 {
5856 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5857 {
5858 pack_fclose(f);
5859 init_tiles(true, &header);
5860 return false;
5861 }
5862 }
5863 else
5864 {
5865 pack_fclose(f);
5866 return false;
5867 }
5868
5869 //combos
5870 if(!p_mgetl(&section_id,f))
5871 {
5872 pack_fclose(f);
5873 return false;
5874 }
5875
5876 if(section_id==ID_COMBOS)
5877 {
5878 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5879 {
5880 pack_fclose(f);
5881 return false;
5882 }
5883 }
5884 else
5885 {
5886 pack_fclose(f);
5887 return false;
5888 }
5889
5890 //palettes
5891 if(!p_mgetl(&section_id,f))
5892 {
5893 pack_fclose(f);
5894 return false;
5895 }
5896
5897 if(section_id==ID_CSETS)
5898 {
5899 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5900 {
5901 pack_fclose(f);
5902 return false;
5903 }
5904 }
5905 else
5906 {
5907 pack_fclose(f);
5908 return false;
5909 }
5910
5911 //items
5912 if(!p_mgetl(&section_id,f))
5913 {
5914 pack_fclose(f);
5915 return false;
5916 }
5917
5918 if(section_id==ID_ITEMS)
5919 {
5920 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5921 {
5922 pack_fclose(f);
5923 return false;
5924 }
5925 }
5926 else
5927 {
5928 pack_fclose(f);
5929 return false;
5930 }
5931
5932 //weapons
5933 if(!p_mgetl(&section_id,f))
5934 {
5935 pack_fclose(f);
5936 return false;
5937 }
5938
5939 if(section_id==ID_WEAPONS)
5940 {
5941 if(readweapons(f, &header)!=0)
5942 {
5943 pack_fclose(f);
5944 return false;
5945 }
5946 }
5947 else
5948 {
5949 pack_fclose(f);
5950 return false;
5951 }
5952
5953 //read the triforce pieces info and make sure it worked
5954 //really do this?
5955
5956 //read the game icons info and make sure it worked
5957 if(!p_mgetl(&section_id,f))
5958 {
5959 pack_fclose(f);
5960 return false;
5961 }
5962
5963 if(section_id==ID_ICONS)
5964 {
5965 if(readgameicons(f, &header, &QMisc)!=0)
5966 {
5967 pack_fclose(f);
5968 return false;
5969 }
5970 }
5971 else
5972 {
5973 pack_fclose(f);
5974 return false;
5975 }
5976
5977 //read the misc colors info and map styles info and make sure it worked
5978 if(!p_mgetl(&section_id,f))
5979 {
5980 pack_fclose(f);
5981 return false;
5982 }
5983
5984 if(section_id==ID_COLORS)
5985 {
5986 if(readmisccolors(f, &header, &QMisc)!=0)
5987 {
5988 pack_fclose(f);
5989 return false;
5990 }
5991 }
5992 else
5993 {
5994 pack_fclose(f);
5995 return false;
5996 }
5997
5998 //read the door combo sets and make sure it worked
5999 if(!p_mgetl(&section_id,f))
6000 {
6001 pack_fclose(f);
6002 return false;
6003 }
6004
6005 if(section_id==ID_DOORS)
6006 {
6007 if(readdoorcombosets(f, &header)!=0)
6008 {
6009 pack_fclose(f);
6010 return false;
6011 }
6012 }
6013 else
6014 {
6015 pack_fclose(f);
6016 return false;
6017 }
6018
6019 //read the template screens and make sure it worked
6020 //really do this?
6021
6022 //yay! it worked! close the file and say everything was ok.
6023 loadlvlpal(Color);
6024 setup_combo_animations();
6025 setup_combo_animations2();
6026 pack_fclose(f);
6027 return true;
6028 }
6029
6030 bool save_zgp(const char *path)
6031 {
6032 reset_combo_animations();
6033 reset_combo_animations2();
6034
6035 //open the file
6036 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6037
6038 if(!f)
6039 return false;
6040
6041 dword section_id=ID_GRAPHICSPACK;
6042 dword section_version=V_GRAPHICSPACK;
6043
6044 //section id
6045 if(!p_mputl(section_id,f))
6046 {
6047 return 1;
6048 }
6049
6050 //section version info
6051 if(!p_iputw(section_version,f))
6052 {
6053 return 2;
6054 }
6055
6056 if(!write_deprecated_section_cversion(section_version,f))
6057 {
6058 return 3;
6059 }
6060
6061 //tiles
6062 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6063 {
6064 pack_fclose(f);
6065 return false;
6066 }
6067
6068 //combos
6069 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6070 {
6071 pack_fclose(f);
6072 return false;
6073 }
6074
6075 //palettes
6076 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6077 {
6078 pack_fclose(f);
6079 return false;
6080 }
6081
6082 //items
6083 if(writeitems(f, &header)!=0)
6084 {
6085 pack_fclose(f);
6086 return false;
6087 }
6088
6089 //weapons
6090 if(writeweapons(f, &header)!=0)
6091 {
6092 pack_fclose(f);
6093 return false;
6094 }
6095
6096 //write the triforce pieces info and make sure it worked
6097 //really do this?
6098
6099 //write the game icons info and make sure it worked
6100 if(writegameicons(f, &header)!=0)
6101 {
6102 pack_fclose(f);
6103 return false;
6104 }
6105
6106 //write the misc colors info and map styles info and make sure it worked
6107 if(writemisccolors(f, &header)!=0)
6108 {
6109 pack_fclose(f);
6110 return false;
6111 }
6112
6113 //write the door combo sets and make sure it worked
6114 if(writedoorcombosets(f, &header)!=0)
6115 {
6116 pack_fclose(f);
6117 return false;
6118 }
6119
6120 //write the template screens and make sure it worked
6121 //really do this?
6122
6123 pack_fclose(f);
6124 return true;
6125 }
6126
6127 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6128 {
6129 //open the file
6130 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6131
6132 if(!f)
6133 return false;
6134
6135 dword section_id=ID_SUBSCREEN;
6136 dword s_version=V_SUBSCREEN;
6137
6138 if(!p_mputl(section_id,f))
6139 {
6140 pack_fclose(f);
6141 return false;
6142 }
6143
6144 if(!p_iputw(s_version,f))
6145 {
6146 pack_fclose(f);
6147 return false;
6148 }
6149
6150 if(!write_deprecated_section_cversion(s_version,f))
6151 {
6152 pack_fclose(f);
6153 return false;
6154 }
6155
6156 if(savefrom.write(f))
6157 {
6158 pack_fclose(f);
6159 return false;
6160 }
6161
6162 pack_fclose(f);
6163 return true;
6164 }
6165
6166 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6167 {
6168 //open the file
6169 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6170
6171 if(!f)
6172 return false;
6173
6174 dword section_id;
6175 dword s_version;
6176
6177 if(!p_mgetl(&section_id,f))
6178 {
6179 pack_fclose(f);
6180 return false;
6181 }
6182
6183 if(section_id!=ID_SUBSCREEN)
6184 {
6185 pack_fclose(f);
6186 return false;
6187 }
6188
6189 if(!p_igetw(&s_version,f))
6190 {
6191 pack_fclose(f);
6192 return false;
6193 }
6194
6195 if(!read_deprecated_section_cversion(f))
6196 {
6197 pack_fclose(f);
6198 return false;
6199 }
6200
6201 if(s_version < 8)
6202 {
6203 subscreen_group g;
6204 memset(&g,0,sizeof(subscreen_group));
6205 if(read_one_old_subscreen(f,&g,s_version)!=0)
6206 {
6207 pack_fclose(f);
6208 return false;
6209 }
6210 if(g.ss_type != loadto.sub_type)
6211 {
6212 pack_fclose(f);
6213 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6214 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6215 return false;
6216 }
6217 loadto.clear();
6218 if(g.objects[0].type != ssoNULL)
6219 loadto.load_old(g);
6220 }
6221 else
6222 {
6223 ZCSubscreen tmp = ZCSubscreen();
6224 if (tmp.read(f, s_version))
6225 {
6226 pack_fclose(f);
6227 return false;
6228 }
6229 if(tmp.sub_type != loadto.sub_type)
6230 {
6231 pack_fclose(f);
6232 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6233 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6234 return false;
6235 }
6236 loadto.clear();
6237 loadto = tmp;
6238 }
6239
6240 pack_fclose(f);
6241 return true;
6242 }
6243
6244 bool setMapCount2(int32_t c)
6245 {
6246 int32_t oldmapcount=map_count;
6247 int32_t cur_map=Map.getCurrMap();
6248
6249 bound(c,1,MAXMAPS);
6250 map_count=c;
6251
6252 try
6253 {
6254 TheMaps.resize(c*MAPSCRS);
6255 Map.force_refr_pointer();
6256 map_infos.resize(c);
6257 }
6258 catch(...)
6259 {
6260 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6261 return false;
6262 }
6263
6264 bound(cur_map,0,c-1);
6265 if(map_count>oldmapcount)
6266 {
6267 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6268 {
6269 // copy the default palette to the new maps
6270 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6271
6272 Map.setCurrMap(mc);
6273 for(int32_t ms=0; ms<MAPSCRS; ms++)
6274 Map.clearscr(ms);
6275 }
6276 Map.setCurrMap(cur_map);
6277 }
6278 else
6279 {
6280 Map.setCurrMap(cur_map);
6281 if(!layers_valid(Map.CurrScr()))
6282 fix_layers(Map.CurrScr(), false);
6283
6284 for(int32_t i=0; i<MAXDMAPS; i++)
6285 {
6286 if(DMaps[i].map>=map_count)
6287 {
6288 DMaps[i].map=map_count-1;
6289 }
6290 }
6291 }
6292
6293 return true;
6294 }
6295
6296 extern BITMAP *bmap;
6297
6298 static bool loading_file_new = false;
6299 int32_t init_quest(std::string tileset_path)
6300 {
6301 if (tileset_path.empty())
6302 tileset_path = DEFAULT_TILESET;
6303
6304 loading_file_new = true;
6305 load_quest(tileset_path.c_str());
6306 loading_file_new = false;
6307
6308 set_window_title("ZC Editor - Untitled Quest");
6309 zinit.last_map = 0;
6310 zinit.last_screen = 0;
6311
6312 if(bmap != NULL)
6313 {
6314 destroy_bitmap(bmap);
6315 bmap=NULL;
6316 }
6317
6318 return 0;
6319 }
6320
6321 void set_questpwd(std::string_view pwd, bool use_keyfile)
6322 {
6323 header.use_keyfile=use_keyfile;
6324
6325 // string_view actually has some quirks that make it less than ideal here.
6326 // It'd probably be best to replace it, but this works for now.
6327 memset(header.password, 0, 256);
6328 strcpy(header.password, pwd.data());
6329 header.dirty_password=true;
6330
6331 cvs_MD5Context ctx;
6332 cvs_MD5Init(&ctx);
6333 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6334 cvs_MD5Final(header.pwd_hash, &ctx);
6335 }
6336
6337
6338 bool is_null_pwd_hash(uint8_t *pwd_hash)
6339 {
6340 cvs_MD5Context ctx;
6341 uint8_t md5sum[16];
6342 char pwd[2]="";
6343
6344 cvs_MD5Init(&ctx);
6345 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6346 cvs_MD5Final(md5sum, &ctx);
6347
6348 return (memcmp(md5sum,pwd_hash,16)==0);
6349 }
6350
6351 static DIALOG pwd_dlg[] =
6352 {
6353 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6354 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6355 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6356 // 2 (filename)
6357 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6358 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6359 // 4 (challenge hash)
6360 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6361 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6362 // 6 (password)
6363 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6364 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6365 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6366 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6367 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6368 };
6369
6370 int32_t reverse_string(char* str)
6371 {
6372
6373 if(NULL==str)
6374 {
6375 return -1; //no string
6376 }
6377
6378 int32_t l=(int32_t)strlen(str)-1; //get the string length
6379
6380 if(1==l)
6381 {
6382 return 1;
6383 }
6384
6385 char c;
6386
6387 for(int32_t x=0; x < l; x++,l--)
6388 {
6389 c = str[x];
6390 str[x] = str[l];
6391 str[l] = c;
6392 }
6393
6394 return 0;
6395 }
6396
6397 #ifdef __GNUC__
6398 #pragma GCC diagnostic push
6399 #pragma GCC diagnostic ignored "-Wunreachable-code"
6400 #endif
6401
6402 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6403 {
6404
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6405 11 return 1;
6406
6407 #ifdef __EMSCRIPTEN__
6408 return 1;
6409 #endif
6410
6411 //Protection against compiling a release version with password protection off.
6412 static bool passguard = false;
6413
6414 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6415 #define MUST_HAVE_PASSWORD
6416 passguard = true;
6417 #endif
6418
6419 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6420 #if (defined _MSC_VER || defined _NPASS)
6421 return 1;
6422 #endif
6423 #endif
6424 if(devpwd()) return 1;
6425
6426 char hash_string[33];
6427
6428 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6429 {
6430 return 1;
6431 }
6432
6433 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6434 return true;
6435
6436 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6437 pwd_dlg[2].dp=get_filename(filename);
6438 cvs_MD5Context ctx;
6439 uint8_t md5sum[16]={0};
6440 char response[33]="";
6441 char prompt[256]="";
6442
6443 memcpy(md5sum, hdr->pwd_hash, 16);
6444
6445 for(int32_t i=0; i<300; ++i)
6446 {
6447 for(int32_t j=0; j<16; ++j)
6448 {
6449 sprintf(response+j*2, "%02x", md5sum[j]);
6450 }
6451
6452 if(i&1)
6453 {
6454 reverse_string(response);
6455 }
6456
6457 if(i==149)
6458 {
6459 strcpy(hash_string, response);
6460 }
6461
6462 cvs_MD5Init(&ctx);
6463 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6464 cvs_MD5Final(md5sum, &ctx);
6465 }
6466
6467 pwd_dlg[4].dp=hash_string;
6468
6469 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6470 {
6471 sprintf(prompt,"%s",response);
6472 }
6473
6474 pwd_dlg[6].dp=prompt;
6475
6476 large_dialog(pwd_dlg);
6477
6478 int32_t cancel = do_zqdialog(pwd_dlg,6);
6479
6480 if(cancel == 8)
6481 return 2;
6482
6483 bool ret=check_questpwd(hdr, prompt);
6484
6485 if(!ret)
6486 {
6487 ret=(strcmp(response,prompt)==0);
6488 }
6489 return ret ? 1 : 0;
6490 11 }
6491
6492 void set_rules(byte* newrules);
6493 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6494 {
6495 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6496
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6497 {
6498
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6499
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6500 "\nWould you like to apply them?"
6501 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6502 11 [&](bool ret,bool dsa)
6503 {
6504 if(ret)
6505 {
6506 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6507 }
6508 if(dsa)
6509 {
6510 zc_set_config("zquest",cfg,1);
6511 }
6512 },
6513
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6514 0,false, //timeout - none
6515 true //"Don't show this again"
6516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6517 11 }
6518 11 }
6519
6520 #ifdef __GNUC__
6521 #pragma GCC diagnostic pop
6522 #endif
6523
6524 11 int32_t load_quest(const char *filename, bool show_progress)
6525 {
6526 char buf[2048];
6527 byte skip_flags[4];
6528
6529 11 dword tileset_flags = 0;
6530
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6531 {
6532 44 skip_flags[i]=0;
6533 44 }
6534
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6535 7634 set_qr(i,0);
6536 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6537
6538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6539 {
6540 init_quest(DEFAULT_TILESET);
6541 }
6542 else
6543 {
6544 11 int32_t accessret = quest_access(filename, &header);
6545
6546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6547 {
6548 init_quest(DEFAULT_TILESET);
6549
6550 if(accessret == 0)
6551 ret=qe_pwd;
6552 else
6553 ret=qe_cancel;
6554 }
6555 else
6556 {
6557 11 Map.clear();
6558 11 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6559 11 Map.setCurrScr(zinit.last_screen);
6560
6561
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6562
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6563
6564 extern int32_t current_mappage;
6565 11 current_mappage = 0;
6566 11 bool found_default = false;
6567
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6568 {
6569 83 auto &pg = map_page[q];
6570
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6571 {
6572 2 current_mappage = q;
6573 2 break;
6574 }
6575
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6576 72 continue;
6577 else
6578 {
6579 9 current_mappage = q;
6580 9 found_default = true;
6581 }
6582 9 }
6583
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6584
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6585
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6586 11 saved = true;
6587
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6588
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6589
6590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6591 {
6592 destroy_bitmap(bmap);
6593 bmap=NULL;
6594 }
6595
6596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6597 {
6598 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6599 set_window_title(buf);
6600 }
6601 11 }
6602 }
6603
6604 11 Map.ClearCommandHistory();
6605
6606
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6607 {
6608 void load_size_poses();
6609 load_size_poses();
6610 }
6611
6612 11 return ret;
6613 }
6614
6615 int32_t load_tileset(const char *filename, dword tsetflags)
6616 {
6617 byte skip_flags[4];
6618
6619 for(int32_t i=0; i<4; ++i)
6620 skip_flags[i]=0;
6621 for(int32_t i=0; i<qr_MAX; i++)
6622 set_qr(i,0);
6623 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6624
6625 if(ret!=qe_OK)
6626 init_quest(DEFAULT_TILESET);
6627 else
6628 {
6629 if(tsetflags & TILESET_BUGFIX)
6630 applyRuleTemplate(ruletemplateFixCompat);
6631 if(tsetflags & TILESET_SCR_BUGFIX)
6632 applyRuleTemplate(ruletemplateFixZSCompat);
6633
6634 int32_t accessret = quest_access(filename, &header);
6635
6636 if(accessret != 1)
6637 {
6638 init_quest(DEFAULT_TILESET);
6639
6640 if(accessret == 0)
6641 ret=qe_pwd;
6642 else
6643 ret=qe_cancel;
6644 }
6645 else
6646 {
6647 Map.clear();
6648 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6649 Map.setCurrScr(zinit.last_screen);
6650 extern int32_t current_mappage;
6651 current_mappage = 0;
6652 bool found_default = false;
6653 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6654 {
6655 auto &pg = map_page[q];
6656 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6657 {
6658 current_mappage = q;
6659 break;
6660 }
6661 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6662 continue;
6663 else
6664 {
6665 current_mappage = q;
6666 found_default = true;
6667 }
6668 }
6669 refresh(rALL);
6670 refresh_pal();
6671 set_rules(quest_rules);
6672
6673 if(bmap != NULL)
6674 {
6675 destroy_bitmap(bmap);
6676 bmap=NULL;
6677 }
6678
6679 set_window_title("ZC Editor - Untitled Quest");
6680 first_save = saved = false;
6681 memset(filepath,0,255);
6682 memset(temppath,0,255);
6683 }
6684 }
6685
6686 Map.ClearCommandHistory();
6687
6688 return ret;
6689 }
6690
6691 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6692 {
6693
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6694 new_return(1);
6695
6696
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6697 new_return(2);
6698
6699
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6700 new_return(3);
6701
6702
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6703 new_return(4);
6704
6705
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6706 {
6707
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6708 new_return(5);
6709
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6710 new_return(6);
6711 1363650 }
6712
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6713 new_return(7);
6714
6715
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6716 new_return(8);
6717
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6718 new_return(9);
6719
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6720 new_return(10);
6721
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6722 new_return(11);
6723
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6724 new_return(12);
6725
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6726 new_return(13);
6727
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6728 new_return(14);
6729
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6730 new_return(15);
6731
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6732 new_return(16);
6733
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6734 new_return(17);
6735
6736
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6737 new_return(18);
6738
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6740 new_return(19);
6741
6742
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6743 new_return(20);
6744
6745
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6746 new_return(21);
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6748 new_return(22);
6749
6750
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6751 new_return(23);
6752
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6753 new_return(24);
6754
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6755 new_return(25);
6756
6757
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6758 new_return(26);
6759
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6760
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6761 new_return(27);
6762
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6763 new_return(28);
6764 272730 return 0;
6765 }
6766
6767 130 bool write_midi(MIDI *m,PACKFILE *f)
6768 {
6769 int32_t c;
6770
6771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6772
6773
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6774 {
6775
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6776
6777
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6778 {
6779
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6780 return false;
6781 1264 }
6782 4160 }
6783
6784 130 return true;
6785 130 }
6786
6787 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6788 {
6789 9 dword section_id=ID_HEADER;
6790 9 dword section_version=V_HEADER;
6791 9 dword section_size=0;
6792
6793 //file header string
6794
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6795 {
6796 new_return(1);
6797 }
6798
6799 //section id
6800
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6801 {
6802 new_return(2);
6803 }
6804
6805 //section version info
6806
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6807 {
6808 new_return(3);
6809 }
6810
6811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6812 {
6813 new_return(4);
6814 }
6815
6816
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6817 {
6818 18 fake_pack_writing=(writecycle==0);
6819
6820 //section size
6821
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6822 {
6823 new_return(5);
6824 }
6825
6826 18 writesize=0;
6827
6828 //finally... section data
6829
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6830 {
6831 new_return(6);
6832 }
6833
6834
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6835 {
6836 new_return(7);
6837 }
6838
6839
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6840 {
6841 new_return(8);
6842 }
6843
6844
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6845 {
6846 new_return(10);
6847 }
6848
6849
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6850 {
6851 new_return(11);
6852 }
6853
6854
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6855 {
6856 new_return(12);
6857 }
6858
6859
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6860 {
6861 new_return(13);
6862 }
6863
6864
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6865 {
6866 new_return(14);
6867 }
6868
6869
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6870 {
6871 new_return(15);
6872 }
6873
6874
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6875 {
6876 new_return(16);
6877 }
6878
6879
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6880 {
6881 new_return(17);
6882 }
6883
6884
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6885 {
6886 new_return(19);
6887 }
6888
6889
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6890 //this is for map count, it seems. -Z
6891 {
6892 new_return(20);
6893 }
6894
6895 18 auto version = getVersion();
6896
6897
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6898 {
6899 new_return(21);
6900 }
6901
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6902 {
6903 new_return(22);
6904 }
6905
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6906 {
6907 new_return(23);
6908 }
6909 // Fourth component is deprecated.
6910
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6911 {
6912 new_return(24);
6913 }
6914
6915 // Numerous prerelease stages is deprecated.
6916
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6917 {
6918 new_return(25);
6919 }
6920
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6921 {
6922 new_return(26);
6923 }
6924
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6925 {
6926 new_return(27);
6927 }
6928
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6929 {
6930 new_return(28);
6931 }
6932
6933
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6934 {
6935 new_return(29);
6936 }
6937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6938 {
6939 new_return(30);
6940 }
6941
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6942 {
6943 new_return(31);
6944 }
6945
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6946 {
6947 new_return(32);
6948 }
6949
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6950 {
6951 new_return(33);
6952 }
6953
6954 // This is no longer set to anything.
6955 const char* tempsig[256];
6956 18 memset(tempsig, 0, 256);
6957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6958 {
6959 new_return(34);
6960 }
6961
6962 char tempcompilersig[256];
6963 18 memset(tempcompilersig, 0, 256);
6964 18 strcpy(tempcompilersig, COMPILER_NAME);
6965
6966
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6967 {
6968 new_return(35);
6969 }
6970
6971 char tempcompilerversion[256];
6972 18 memset(tempcompilerversion, 0, 256);
6973 #ifdef _MSC_VER
6974 zc_itoa(_MSC_VER,tempcompilerversion,10);
6975 #else
6976 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6977 #endif
6978
6979
6980
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6981 {
6982 new_return(36);
6983 }
6984
6985
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6986 {
6987 new_return(37);
6988 }
6989
6990 // V_ZC_COMPILERSIG - a deprecated version field.
6991
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6992 {
6993 new_return(38);
6994 }
6995 #ifdef _MSC_VER
6996 if(!p_iputl((_MSC_VER / 100),f))
6997 {
6998 new_return(39);
6999 }
7000 #else
7001
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7002 {
7003 new_return(39);
7004 }
7005 #endif
7006
7007
7008
7009 #ifdef _MSC_VER
7010 if(!p_iputl((_MSC_VER % 100),f))
7011 {
7012 new_return(41);
7013 }
7014 #else
7015
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7016 {
7017 new_return(41);
7018 }
7019 #endif
7020
7021 #ifdef _MSC_VER
7022 # if _MSC_VER >= 1400
7023 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7024 {
7025 new_return(40);
7026 }
7027 # else
7028 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7029 {
7030 new_return(40);
7031 }
7032 #endif
7033 #else
7034
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7035 {
7036 new_return(40);
7037 }
7038 #endif
7039
7040 #ifdef _MSC_VER
7041 if(!p_iputl((_MSC_BUILD),f))
7042 {
7043 new_return(42);
7044 }
7045 #else
7046
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7047 {
7048 new_return(42);
7049 }
7050 #endif
7051
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7052 {
7053 new_return(43);
7054 }
7055
7056 // Modules were removed (replaced by zinfo).
7057 char tempmodulename[1024];
7058 18 memset(tempmodulename, 0, 1024);
7059
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7060 {
7061 new_return(44);
7062 }
7063
7064 char tempdate[256];
7065 18 memset(tempdate, 0, 256);
7066 18 strcpy(tempdate, __DATE__);
7067
7068
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7069 {
7070 new_return(45);
7071 }
7072 char temptime[256];
7073 18 memset(temptime, 0, 256);
7074 18 strcpy(temptime, __TIME__);
7075
7076
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7077 {
7078 new_return(46);
7079 }
7080
7081
7082 char temptimezone[6];
7083 18 memset(temptimezone, 0, 6);
7084 18 strcpy(temptimezone, __TIMEZONE__);
7085
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7086 {
7087 new_return(47);
7088 }
7089
7090
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7091 {
7092 new_return(48);
7093 }
7094
7095
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7096 {
7097 new_return(49);
7098 }
7099
7100
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7101 {
7102 new_return(50);
7103 }
7104
7105
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7106 {
7107 9 section_size=writesize;
7108 9 }
7109 18 }
7110
7111
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7112 {
7113 char ebuf[80];
7114 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7115 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7116 }
7117
7118 9 new_return(0);
7119 }
7120
7121 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7122 {
7123 //these are here to bypass compiler warnings about unused arguments
7124 9 Header=Header;
7125
7126 9 dword section_id=ID_RULES;
7127 9 dword section_version=V_RULES;
7128 9 dword section_size=0;
7129
7130 //section id
7131
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7132 {
7133 new_return(1);
7134 }
7135
7136 //section version info
7137
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7138 {
7139 new_return(2);
7140 }
7141
7142
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7143 {
7144 new_return(3);
7145 }
7146
7147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7148 {
7149 new_return(6);
7150 }
7151
7152
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7153 {
7154 18 fake_pack_writing=(writecycle==0);
7155
7156 //section size
7157
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7158 {
7159 new_return(4);
7160 }
7161
7162 18 writesize=0;
7163
7164 //finally... section data
7165
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7166 {
7167 new_return(5);
7168 }
7169
7170
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7171 {
7172 9 section_size=writesize;
7173 9 }
7174 18 }
7175
7176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7177 {
7178 char ebuf[80];
7179 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7180 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7181 }
7182
7183 9 new_return(0);
7184 }
7185
7186
7187 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7188 {
7189 //these are here to bypass compiler warnings about unused arguments
7190 9 Header=Header;
7191
7192 9 dword section_id=ID_DOORS;
7193 9 dword section_version=V_DOORS;
7194 9 dword section_size=0;
7195
7196 //section id
7197
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7198 {
7199 new_return(1);
7200 }
7201
7202 //section version info
7203
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7204 {
7205 new_return(2);
7206 }
7207
7208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7209 {
7210 new_return(3);
7211 }
7212
7213
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7214 {
7215 18 fake_pack_writing=(writecycle==0);
7216
7217 //section size
7218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7219 {
7220 new_return(4);
7221 }
7222
7223 18 writesize=0;
7224
7225 //finally... section data
7226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7227 {
7228 new_return(5);
7229 }
7230
7231
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7232 {
7233 //name
7234 char name[21];
7235 320 memset(name, 21, (char)0);
7236 320 strcpy(name, DoorComboSetNames[i].c_str());
7237
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7238 {
7239 new_return(6);
7240 }
7241
7242 //up door
7243
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7244 {
7245
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7246 {
7247
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7248 {
7249 new_return(7);
7250 }
7251 11520 }
7252 2880 }
7253
7254
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7255 {
7256
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7257 {
7258
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7259 {
7260 new_return(8);
7261 }
7262 11520 }
7263 2880 }
7264
7265 //down door
7266
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7267 {
7268
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7269 {
7270
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7271 {
7272 new_return(9);
7273 }
7274 11520 }
7275 2880 }
7276
7277
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7278 {
7279
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7280 {
7281
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7282 {
7283 new_return(10);
7284 }
7285 11520 }
7286 2880 }
7287
7288
7289 //left door
7290
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7291 {
7292
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7293 {
7294
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7295
7296 {
7297 new_return(11);
7298 }
7299 17280 }
7300 2880 }
7301
7302
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7303 {
7304
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7305 {
7306
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7307 {
7308 new_return(12);
7309 }
7310 17280 }
7311 2880 }
7312
7313 //right door
7314
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7315 {
7316
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7317 {
7318
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7319 {
7320 new_return(13);
7321 }
7322 17280 }
7323 2880 }
7324
7325
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7326 {
7327
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7328 {
7329
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7330 {
7331 new_return(14);
7332 }
7333 17280 }
7334 2880 }
7335
7336
7337 //up bomb rubble
7338
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7339 {
7340
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7341 {
7342 new_return(15);
7343 }
7344 640 }
7345
7346
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7347 {
7348
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7349 {
7350 new_return(16);
7351 }
7352 640 }
7353
7354 //down bomb rubble
7355
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7356 {
7357
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7358 {
7359 new_return(17);
7360 }
7361 640 }
7362
7363
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7364 {
7365
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7366 {
7367 new_return(18);
7368 }
7369 640 }
7370
7371 //left bomb rubble
7372
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7373 {
7374
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7375 {
7376 new_return(19);
7377 }
7378 960 }
7379
7380
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7381 {
7382
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7383 {
7384 new_return(20);
7385 }
7386 960 }
7387
7388 //right bomb rubble
7389
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7390 {
7391
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7392 {
7393 new_return(21);
7394 }
7395 960 }
7396
7397
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7398 {
7399
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7400 {
7401 new_return(22);
7402 }
7403 960 }
7404
7405 //walkthrough stuff
7406
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7407 {
7408
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7409 {
7410 new_return(23);
7411 }
7412 1280 }
7413
7414
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7415 {
7416
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7417 {
7418 new_return(24);
7419 }
7420 1280 }
7421
7422 //flags
7423
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7424 {
7425
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7426 {
7427 new_return(25);
7428 }
7429 640 }
7430 320 }
7431
7432
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7433 {
7434 9 section_size=writesize;
7435 9 }
7436 18 }
7437
7438
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7439 {
7440 char ebuf[80];
7441 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7442 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7443 }
7444
7445 9 new_return(0);
7446 }
7447
7448 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7449 {
7450 //these are here to bypass compiler warnings about unused arguments
7451 9 version=version;
7452 9 build=build;
7453
7454 9 word dmap_count=count_dmaps();
7455 9 dword section_id=ID_DMAPS;
7456 9 dword section_version=V_DMAPS;
7457 9 dword section_size=0;
7458
7459 //section id
7460
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7461 {
7462 new_return(1);
7463 }
7464
7465 //section version info
7466
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7467 {
7468 new_return(2);
7469 }
7470
7471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7472 {
7473 new_return(3);
7474 }
7475
7476
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7477 {
7478 18 fake_pack_writing=(writecycle==0);
7479
7480 //section size
7481
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7482 {
7483 new_return(4);
7484 }
7485
7486 18 writesize=0;
7487
7488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7490
7491 //finally... section data
7492
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7493 {
7494 new_return(5);
7495 }
7496
7497
7498
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7499 {
7500 9216 DMaps[i].validate_subscreens();
7501
7502
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7503 {
7504 new_return(6);
7505 }
7506
7507
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7508 {
7509 new_return(7);
7510 }
7511
7512
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7513 {
7514 new_return(8);
7515 }
7516
7517
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7518 {
7519 new_return(9);
7520 }
7521
7522
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7523 {
7524 new_return(10);
7525 }
7526
7527
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7528 {
7529 new_return(11);
7530 }
7531
7532
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7533 {
7534 new_return(12);
7535 }
7536
7537
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7538 {
7539 new_return(13);
7540 }
7541
7542
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7543 {
7544
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7545 {
7546 new_return(14);
7547 }
7548 73728 }
7549
7550
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7551 {
7552 new_return(15);
7553 }
7554
7555
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7556 {
7557 new_return(16);
7558 }
7559
7560
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7561 {
7562 new_return(17);
7563 }
7564
7565
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[0],f))
7566 {
7567 new_return(18);
7568 }
7569
7570
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[0],f))
7571 {
7572 new_return(19);
7573 }
7574
7575
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[1],f))
7576 {
7577 new_return(20);
7578 }
7579
7580
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[1],f))
7581 {
7582 new_return(21);
7583 }
7584
7585
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[0],f))
7586 {
7587 new_return(22);
7588 }
7589
7590
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[0],f))
7591 {
7592 new_return(23);
7593 }
7594
7595
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[1],f))
7596 {
7597 new_return(24);
7598 }
7599
7600
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[1],f))
7601 {
7602 new_return(25);
7603 }
7604
7605
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7606 {
7607 new_return(26);
7608 }
7609
7610
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7611 {
7612 new_return(25);
7613 }
7614
7615
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7616 {
7617 new_return(26);
7618 }
7619
7620
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7621 {
7622 new_return(27);
7623 }
7624
7625 byte disabled[32];
7626 9216 memset(disabled,0,32);
7627
7628
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7629 {
7630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359296 times.
2359296 if(DMaps[i].disableditems[j])
7631 {
7632 disabled[j/8] |= (1 << (j%8));
7633 }
7634 2359296 }
7635
7636
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7637 {
7638 new_return(28);
7639 }
7640
7641
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7642 {
7643 new_return(29);
7644 }
7645
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7646 {
7647 new_return(30);
7648 }
7649
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7650 {
7651 new_return(31);
7652 }
7653
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7654 {
7655
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7656 {
7657 new_return(32);
7658 }
7659
7660 73728 }
7661
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7662 {
7663
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7664 {
7665
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7666 {
7667 new_return(33);
7668 }
7669 4792320 }
7670 73728 }
7671
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7672 {
7673 new_return(34);
7674 }
7675
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7676 {
7677 new_return(35);
7678 }
7679
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7680 {
7681
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7682 {
7683 new_return(36);
7684 }
7685 73728 }
7686
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7687 {
7688
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7689 {
7690
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7691 {
7692 new_return(37);
7693 }
7694 4792320 }
7695 73728 }
7696
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7697 {
7698 new_return(38);
7699 }
7700
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7701 {
7702
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7703 {
7704 new_return(39);
7705 }
7706 73728 }
7707
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7708 {
7709
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7710 {
7711
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7712 {
7713 new_return(40);
7714 }
7715 4792320 }
7716 73728 }
7717
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7718 {
7719 new_return(41);
7720 }
7721
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7722 {
7723 new_return(42);
7724 }
7725
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7726 {
7727 new_return(43);
7728 }
7729
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7730 {
7731 new_return(44);
7732 }
7733
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7734 {
7735 new_return(45);
7736 }
7737
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7738 new_return(46);
7739
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7740 new_return(47);
7741
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[i].flags & dmfCUSTOM_GRAVITY)
7742 {
7743 if (!p_iputzf(DMaps[i].dmap_gravity, f))
7744 new_return(48);
7745 if (!p_iputzf(DMaps[i].dmap_terminal_v, f))
7746 new_return(49);
7747 }
7748 9216 }
7749
7750
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7751 {
7752 9 section_size=writesize;
7753 9 }
7754 18 }
7755
7756
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7757 {
7758 char ebuf[80];
7759 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7760 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7761 }
7762
7763 9 new_return(0);
7764 }
7765
7766 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7767 {
7768 //these are here to bypass compiler warnings about unused arguments
7769 9 Header=Header;
7770
7771 9 dword section_id=ID_COLORS;
7772 9 dword section_version=V_COLORS;
7773 9 dword section_size = 0;
7774
7775 //section id
7776
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7777 {
7778 new_return(1);
7779 }
7780
7781
7782 //section version info
7783
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7784 {
7785 new_return(2);
7786 }
7787
7788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7789 {
7790 new_return(3);
7791 }
7792
7793
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7794 {
7795 18 fake_pack_writing=(writecycle==0);
7796
7797 //section size
7798
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7799 {
7800 new_return(4);
7801 }
7802
7803 18 writesize=0;
7804
7805
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7806 {
7807 new_return(5);
7808 }
7809
7810
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7811 {
7812 new_return(6);
7813 }
7814
7815
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7816 {
7817 new_return(7);
7818 }
7819
7820
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7821 {
7822 new_return(8);
7823 }
7824
7825
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7826 {
7827 new_return(9);
7828 }
7829
7830
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7831 {
7832 new_return(10);
7833 }
7834
7835
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7836 {
7837 new_return(11);
7838 }
7839
7840
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7841 {
7842 new_return(12);
7843 }
7844
7845
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7846 {
7847 new_return(13);
7848 }
7849
7850
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7851 {
7852 new_return(14);
7853 }
7854
7855
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7856 {
7857 new_return(15);
7858 }
7859
7860
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7861 {
7862 new_return(16);
7863 }
7864
7865
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7866 {
7867 new_return(17);
7868 }
7869
7870
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7871 {
7872 new_return(18);
7873 }
7874
7875
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7876 {
7877 new_return(19);
7878 }
7879
7880
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7881 {
7882 new_return(20);
7883 }
7884
7885
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7886 {
7887 new_return(21);
7888 }
7889
7890
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7891 {
7892 new_return(22);
7893 }
7894
7895
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7896 {
7897 new_return(23);
7898 }
7899
7900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7901 {
7902 new_return(24);
7903 }
7904
7905
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7906 {
7907 new_return(31);
7908 }
7909
7910
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7911 {
7912 new_return(32);
7913 }
7914
7915
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7916 {
7917 new_return(33);
7918 }
7919
7920
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7921 {
7922 new_return(34);
7923 }
7924
7925
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7926 {
7927 new_return(35);
7928 }
7929
7930
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7931 {
7932 new_return(36);
7933 }
7934
7935
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7936 {
7937 new_return(37);
7938 }
7939
7940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7941 {
7942 new_return(38);
7943 }
7944
7945
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7946 {
7947 new_return(39);
7948 }
7949
7950
7951
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7952 {
7953 9 section_size=writesize;
7954 9 }
7955 18 }
7956
7957
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7958 {
7959 char ebuf[80];
7960 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7961 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7962 }
7963
7964 9 new_return(0);
7965 }
7966
7967 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7968 {
7969 //these are here to bypass compiler warnings about unused arguments
7970 9 Header=Header;
7971
7972 9 dword section_id=ID_ICONS;
7973 9 dword section_version=V_ICONS;
7974 9 dword section_size = 0;
7975
7976 //section id
7977
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7978 {
7979 new_return(1);
7980 }
7981
7982 //section version info
7983
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7984 {
7985 new_return(2);
7986 }
7987
7988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7989 {
7990 new_return(3);
7991 }
7992
7993
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7994 {
7995 18 fake_pack_writing=(writecycle==0);
7996
7997 //section size
7998
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7999 {
8000 new_return(4);
8001 }
8002
8003 18 writesize=0;
8004
8005
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
8006 {
8007
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
8008 {
8009 new_return(5);
8010 }
8011 72 }
8012
8013
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8014 {
8015 9 section_size=writesize;
8016 9 }
8017 18 }
8018
8019
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8020 {
8021 char ebuf[80];
8022 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8023 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8024 }
8025
8026 9 new_return(0);
8027 }
8028
8029 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8030 {
8031 //these are here to bypass compiler warnings about unused arguments
8032 9 Header=Header;
8033
8034 9 dword section_id=ID_MISC;
8035 9 dword section_version=V_MISC;
8036 9 word shops=count_shops(&QMisc);
8037 9 word infos=count_infos(&QMisc);
8038 9 word warprings=count_warprings(&QMisc);
8039 9 word triforces=8;
8040 9 dword section_size = 0;
8041
8042 //section id
8043
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8044 {
8045 new_return(1);
8046 }
8047
8048
8049 //section version info
8050
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8051 {
8052 new_return(2);
8053 }
8054
8055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8056 {
8057 new_return(3);
8058 }
8059
8060
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8061 {
8062 18 fake_pack_writing=(writecycle==0);
8063
8064 //section size
8065
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8066 {
8067 new_return(4);
8068 }
8069
8070 18 writesize=0;
8071
8072 //shops
8073
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8074 {
8075 new_return(5);
8076 }
8077
8078
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8079 {
8080
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8081 {
8082 new_return(6);
8083 }
8084
8085
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8086 {
8087
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8088 {
8089 new_return(7);
8090 }
8091 480 }
8092
8093
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8094 {
8095
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8096 {
8097 new_return(8);
8098 }
8099 480 }
8100
8101
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8102 {
8103
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8104 {
8105 new_return(9);
8106 }
8107 480 }
8108 160 }
8109
8110 //infos
8111
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8112 {
8113 new_return(10);
8114 }
8115
8116
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8117 {
8118
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8119 {
8120 new_return(11);
8121 }
8122
8123
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8124 {
8125
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8126 {
8127 new_return(12);
8128 }
8129 480 }
8130
8131
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8132 {
8133
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8134 {
8135 new_return(13);
8136 }
8137 480 }
8138 160 }
8139
8140 //warp rings
8141
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8142 {
8143 new_return(14);
8144 }
8145
8146
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8147 {
8148
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8149 {
8150
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8151 {
8152 new_return(15);
8153 }
8154 1872 }
8155
8156
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8157 {
8158
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8159 {
8160 new_return(16);
8161 }
8162 1872 }
8163
8164
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8165 {
8166 new_return(17);
8167 }
8168 208 }
8169
8170 //triforce pieces
8171
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8172 {
8173
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8174 {
8175 new_return(18);
8176 }
8177 144 }
8178
8179 //end string
8180
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8181 {
8182 new_return(19);
8183 }
8184
8185 //V_MISC >= 8
8186
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8187 {
8188
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8189 {
8190
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8191 {
8192 new_return(20);
8193 }
8194 480 }
8195 160 }
8196 //V_MISC >= 9
8197
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8198 {
8199
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8200 new_return(21);
8201 576 }
8202
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8203 {
8204
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8205
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8206 new_return(22);
8207 576 }
8208 //V_MISC >= 11
8209
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8210 new_return(23);
8211
8212 //V_MISC >= 12
8213
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8214 {
8215
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8216 new_return(24);
8217 4608 }
8218
8219 //V_MISC >= 13
8220
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8221 {
8222 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8223
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8224 new_return(25);
8225
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8226 {
8227
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8228 new_return(25);
8229
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8230 new_return(25);
8231 3456 }
8232
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8233 new_return(25);
8234
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8235 new_return(25);
8236 1152 }
8237
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8238 {
8239 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8240
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8241 new_return(26);
8242
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8243 {
8244
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8245 new_return(26);
8246
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8247 new_return(26);
8248
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8249 new_return(26);
8250
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8251 new_return(26);
8252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8253 new_return(26);
8254 13824 }
8255 4608 }
8256
8257 //V_MISC >= 14
8258
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8259 {
8260
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8261 new_return(27);
8262 4608 }
8263
8264
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8265 {
8266 9 section_size=writesize;
8267 9 }
8268 18 }
8269
8270
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8271 {
8272 char ebuf[80];
8273 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8274 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8275 }
8276
8277 9 new_return(0);
8278 }
8279
8280 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8281 {
8282 //these are here to bypass compiler warnings about unused arguments
8283 9 Header=Header;
8284
8285 9 dword section_id=ID_ITEMS;
8286 9 dword section_version=V_ITEMS;
8287 // dword section_size=0;
8288 9 dword section_size = 0;
8289
8290 //section id
8291
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8292 {
8293 new_return(1);
8294 }
8295
8296 //section version info
8297
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8298 {
8299 new_return(2);
8300 }
8301
8302
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8303 {
8304 new_return(3);
8305 }
8306
8307
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8308 {
8309 18 fake_pack_writing=(writecycle==0);
8310
8311 //section size
8312
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8313 {
8314 new_return(4);
8315 }
8316
8317 18 writesize=0;
8318
8319 //finally... section data
8320
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8321 {
8322 new_return(5);
8323 }
8324
8325
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8326 {
8327
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8328 {
8329 new_return(5);
8330 }
8331 4608 }
8332
8333
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8334 {
8335
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8336 {
8337 new_return(6);
8338 }
8339
8340
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8341 {
8342 new_return(7);
8343 }
8344
8345
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8346 {
8347 new_return(8);
8348 }
8349
8350
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8351 {
8352 new_return(9);
8353 }
8354
8355
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8356 {
8357 new_return(10);
8358 }
8359
8360
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8361 {
8362 new_return(11);
8363 }
8364
8365
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8366 {
8367 new_return(12);
8368 }
8369
8370
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8371 {
8372 new_return(13);
8373 }
8374
8375
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8376 {
8377 new_return(14);
8378 }
8379
8380
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8381 {
8382 new_return(14);
8383 }
8384
8385
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8386 {
8387 new_return(15);
8388 }
8389
8390
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8391 {
8392 new_return(16);
8393 }
8394
8395
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8396 {
8397 new_return(17);
8398 }
8399
8400
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8401 {
8402 new_return(18);
8403 }
8404
8405
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8406 {
8407 new_return(19);
8408 }
8409
8410
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8411 {
8412 new_return(21);
8413 }
8414
8415
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8416 {
8417 new_return(22);
8418 }
8419
8420
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8421 {
8422 new_return(23);
8423 }
8424
8425
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8426 {
8427
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8428 {
8429 new_return(24);
8430 }
8431 36864 }
8432
8433
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8434 {
8435
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8436 {
8437 new_return(25);
8438 }
8439 9216 }
8440
8441
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8442 {
8443 new_return(26);
8444 }
8445
8446
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8447 {
8448 new_return(27);
8449 }
8450
8451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8452 {
8453 new_return(28);
8454 }
8455
8456
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8457 {
8458 new_return(29);
8459 }
8460
8461
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8462 {
8463 new_return(30);
8464 }
8465
8466
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8467 {
8468 new_return(31);
8469 }
8470
8471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8472 {
8473 new_return(32);
8474 }
8475
8476
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8477 {
8478 new_return(33);
8479 }
8480
8481
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8482 {
8483 new_return(34);
8484 }
8485
8486
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8487 {
8488 new_return(35);
8489 }
8490
8491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8492 {
8493 new_return(36);
8494 }
8495
8496
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8497 {
8498 new_return(37);
8499 }
8500
8501
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8502 {
8503 new_return(38);
8504 }
8505
8506
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8507 {
8508
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8509 {
8510 new_return(39);
8511 }
8512 9216 }
8513
8514
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8515 {
8516 new_return(40);
8517 }
8518
8519
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8520 {
8521 new_return(41);
8522 }
8523
8524
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8525 {
8526 new_return(42);
8527 }
8528
8529
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8530 {
8531 new_return(43);
8532 }
8533
8534
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8535 {
8536 new_return(44);
8537 }
8538
8539
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8540 {
8541 new_return(45);
8542 }
8543
8544
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8545 {
8546 new_return(46);
8547 }
8548
8549
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8550 {
8551 new_return(47);
8552 }
8553
8554
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8555 {
8556 new_return(48);
8557 }
8558
8559
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8560 {
8561 new_return(48);
8562 }
8563
8564 //New itemdata vars -Z
8565 //! version 27
8566
8567
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8568 {
8569 new_return(51);
8570 }
8571
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8572 {
8573 new_return(52);
8574 }
8575
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8576
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8577 {
8578 new_return(53);
8579 }
8580 46080 }
8581 //version 28
8582
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8583 {
8584 new_return(54);
8585 }
8586
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8587 {
8588
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8589 {
8590 new_return(56);
8591 }
8592 9216 }
8593
8594
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8595 {
8596 new_return(57);
8597 }
8598
8599
8600
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8601 {
8602 new_return(58);
8603 }
8604
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8605 {
8606 new_return(59);
8607 }
8608
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8609 {
8610 new_return(60);
8611 }
8612
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8613 {
8614 new_return(61);
8615 }
8616
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8617 {
8618 new_return(62);
8619 }
8620
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8621 {
8622 new_return(63);
8623 }
8624
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8625 {
8626 new_return(64);
8627 }
8628
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8629 {
8630 new_return(73);
8631 }
8632
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8633 {
8634
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8635 {
8636 new_return(74);
8637 }
8638 9216 }
8639
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8640 {
8641 new_return(75);
8642 }
8643
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8644 {
8645 new_return(76);
8646 }
8647
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8648 {
8649 new_return(77);
8650 }
8651
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8652 {
8653 new_return(81);
8654 }
8655
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8656 {
8657 new_return(82);
8658 }
8659
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8660 {
8661 new_return(83);
8662 }
8663
8664
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8665 {
8666
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8667 {
8668 new_return(84);
8669 }
8670 9216 }
8671
8672 //InitD[] labels
8673
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8674 {
8675
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8676 {
8677
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8678 {
8679 new_return(85);
8680 }
8681 2396160 }
8682
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8683 {
8684
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8685 {
8686 new_return(87);
8687 }
8688 2396160 }
8689
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8690 {
8691 new_return(88);
8692 }
8693 36864 }
8694
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8695 {
8696
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8697 {
8698 new_return(89);
8699 }
8700
8701 9216 }
8702
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8703 {
8704 new_return(90);
8705 }
8706
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8707 {
8708 new_return(91);
8709 }
8710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8711
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8712 new_return(92);
8713
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8714 new_return(95);
8715
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8716 new_return(96);
8717
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8718 new_return(97);
8719
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8720 return ret;
8721
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8722 new_return(98);
8723
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8724
8725
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8726 {
8727 9 section_size=writesize;
8728 9 }
8729 18 }
8730
8731
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8732 {
8733 char ebuf[80];
8734 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8735 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8736 }
8737
8738 9 new_return(0);
8739 9 }
8740
8741 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8742 {
8743 //these are here to bypass compiler warnings about unused arguments
8744 9 Header=Header;
8745
8746 9 dword section_id=ID_WEAPONS;
8747 9 dword section_version=V_WEAPONS;
8748 9 dword section_size = 0;
8749
8750 //section id
8751
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8752 {
8753 new_return(1);
8754 }
8755
8756 //section version info
8757
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8758 {
8759 new_return(2);
8760 }
8761
8762
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8763 {
8764 new_return(3);
8765 }
8766
8767
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8768 {
8769 18 fake_pack_writing=(writecycle==0);
8770
8771 //section size
8772
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8773 {
8774 new_return(4);
8775 }
8776
8777 18 writesize=0;
8778
8779 //finally... section data
8780
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8781 {
8782 new_return(5);
8783 }
8784
8785
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8786 {
8787
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8788 {
8789 new_return(5);
8790 }
8791 4608 }
8792
8793
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8794 {
8795
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8796 {
8797 new_return(7);
8798 }
8799
8800
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8801 {
8802 new_return(8);
8803 }
8804
8805
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8806 {
8807 new_return(9);
8808 }
8809
8810
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8811 {
8812 new_return(10);
8813 }
8814
8815
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8816 {
8817 new_return(11);
8818 }
8819
8820
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8821 {
8822 new_return(12);
8823 }
8824
8825
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8826 {
8827 new_return(12);
8828 }
8829 4608 }
8830
8831
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8832 {
8833 9 section_size=writesize;
8834 9 }
8835 18 }
8836
8837
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8838 {
8839 char ebuf[80];
8840 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8841 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8842 }
8843
8844 9 new_return(0);
8845 }
8846
8847 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8848 {
8849
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8850 return qe_invalid;
8851
8852 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8853 12784 bool is_0x80_screen = j >= 0x80;
8854
8855
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8856 return qe_invalid;
8857
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8858 4404 return qe_OK;
8859 //Calculate what needs writing
8860 8380 uint32_t scr_has_flags = 0;
8861
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8862
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8863 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8864
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8865 446 scr_has_flags |= SCRHAS_ITEM;
8866
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8867 28 scr_has_flags |= SCRHAS_TWARP;
8868
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8869 {
8870
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8871
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8872
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8873 {
8874 176 scr_has_flags |= SCRHAS_TWARP;
8875 176 break;
8876 }
8877 32706 }
8878
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8879
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8880 36 scr_has_flags |= SCRHAS_SWARP;
8881
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8882 {
8883
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8884
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8885
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8886 {
8887 4270 scr_has_flags |= SCRHAS_SWARP;
8888 4270 break;
8889 }
8890 16298 }
8891
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8892 44 scr_has_flags |= SCRHAS_WARPRET;
8893
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8894 {
8895
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8896 {
8897 784 scr_has_flags |= SCRHAS_WARPRET;
8898 784 break;
8899 }
8900 30208 }
8901
8902
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8903 scr_has_flags |= SCRHAS_LAYERS;
8904
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8905 {
8906
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8907
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8908 {
8909 966 scr_has_flags |= SCRHAS_LAYERS;
8910 966 break;
8911 }
8912 44532 }
8913
8914
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8915 10 scr_has_flags |= SCRHAS_MAZE;
8916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8917 scr_has_flags |= SCRHAS_MAZE;
8918
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8919 {
8920
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8921 {
8922 scr_has_flags |= SCRHAS_MAZE;
8923 break;
8924 }
8925 33480 }
8926
8927
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8928
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8929
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8930 2968 scr_has_flags |= SCRHAS_D_S_U;
8931
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8932 {
8933
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8934 {
8935 5212 scr_has_flags |= SCRHAS_D_S_U;
8936 5212 break;
8937 }
8938 800 }
8939
8940
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8941
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8942
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8943
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8944
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8945
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8946 8380 scr_has_flags |= SCRHAS_FLAGS;
8947
8948
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8949 58 scr_has_flags |= SCRHAS_ENEMY;
8950
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8951 {
8952
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8953 {
8954 1014 scr_has_flags |= SCRHAS_ENEMY;
8955 1014 break;
8956 }
8957 73086 }
8958
8959
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
8960 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
8961 8380 scr_has_flags |= SCRHAS_CARRY;
8962
8963
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
8964 22 scr_has_flags |= SCRHAS_SCRIPT;
8965
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
8966 {
8967
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
8968 {
8969 scr_has_flags |= SCRHAS_SCRIPT;
8970 break;
8971 }
8972 66864 }
8973
8974
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
8975 {
8976
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
8977
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
8978
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
8979 {
8980 3076 scr_has_flags |= SCRHAS_SECRETS;
8981 3076 break;
8982 }
8983 680916 }
8984
8985
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
8986 {
8987
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
8988
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
8989 {
8990 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
8991 5360 break;
8992 }
8993 568532 }
8994
8995
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
8996
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
8997
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
8998 || screen.timedwarptics || screen.screen_midi != -1
8999 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9000 8380 scr_has_flags |= SCRHAS_MISC;
9001
9002
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9003 return qe_invalid;
9004
9005 //Write stuff
9006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9007 {
9008
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9009 return qe_invalid;
9010
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9011 return qe_invalid;
9012
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9013 return qe_invalid;
9014
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9015 return qe_invalid;
9016
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9017 return qe_invalid;
9018
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9019 return qe_invalid;
9020
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9021 return qe_invalid;
9022 8380 }
9023
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9024 {
9025
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9026 return qe_invalid;
9027
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9028 return qe_invalid;
9029
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9030 return qe_invalid;
9031
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9032 return qe_invalid;
9033 446 }
9034
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9035 {
9036
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9037 return qe_invalid;
9038 4374 }
9039
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9040 {
9041
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9042 {
9043
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9044 return qe_invalid;
9045 816 }
9046
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9047 {
9048
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9049 return qe_invalid;
9050 816 }
9051
9052
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9053 {
9054
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9055 return qe_invalid;
9056 816 }
9057
9058
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9059 return qe_invalid;
9060 204 }
9061
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9062 {
9063
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9064 {
9065
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9066 return qe_invalid;
9067 17224 }
9068
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9069 {
9070
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9071 return qe_invalid;
9072 17224 }
9073
9074
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9075 {
9076
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9077 return qe_invalid;
9078 17224 }
9079
9080
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9081 return qe_invalid;
9082
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9083 return qe_invalid;
9084 4306 }
9085
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9086 {
9087
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9088 {
9089
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9090 return qe_invalid;
9091 3312 }
9092
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9093 {
9094
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9095 return qe_invalid;
9096 3312 }
9097
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9098 return qe_invalid;
9099
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9100 return qe_invalid;
9101 828 }
9102
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9103 {
9104
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9105 {
9106
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9107 return qe_invalid;
9108 5796 }
9109
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9110 {
9111
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9112 return qe_invalid;
9113 5796 }
9114
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9115 {
9116
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9117 return qe_invalid;
9118 5796 }
9119
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9120 return qe_invalid;
9121
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9122 return qe_invalid;
9123 966 }
9124
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9125 {
9126
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9127 {
9128
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9129 return qe_invalid;
9130 40 }
9131
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9132 return qe_invalid;
9133
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9134 return qe_invalid;
9135 10 }
9136
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9137 {
9138
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9139 return qe_invalid;
9140
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9141 {
9142
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9143 return qe_invalid;
9144 32720 }
9145
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9146 return qe_invalid;
9147
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9148 return qe_invalid;
9149
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9150 return qe_invalid;
9151
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9152 return qe_invalid;
9153 8180 }
9154
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9155 {
9156
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9157 return qe_invalid;
9158
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9159 return qe_invalid;
9160
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9161 return qe_invalid;
9162
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9163 return qe_invalid;
9164
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9165 return qe_invalid;
9166
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9167 return qe_invalid;
9168
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9169 return qe_invalid;
9170
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9171 return qe_invalid;
9172
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9173 return qe_invalid;
9174
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9175 return qe_invalid;
9176
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9177 return qe_invalid;
9178 1294 }
9179
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9180 {
9181
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9182 {
9183
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9184 return qe_invalid;
9185 10720 }
9186
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9187 return qe_invalid;
9188 1072 }
9189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9190 {
9191
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9192 return qe_invalid;
9193
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9194 return qe_invalid;
9195
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9196 return qe_invalid;
9197
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9198 return qe_invalid;
9199
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9200 return qe_invalid;
9201
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9202 return qe_invalid;
9203 8380 }
9204
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9205 {
9206
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9207 return qe_invalid;
9208
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9209 return qe_invalid;
9210
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9211 {
9212
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9213 return qe_invalid;
9214 176 }
9215 22 }
9216
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9217 {
9218
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9219 {
9220
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9221 return qe_invalid;
9222 393728 }
9223
9224
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9225 {
9226
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9227 return qe_invalid;
9228 393728 }
9229
9230
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9231 {
9232
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9233 return qe_invalid;
9234 393728 }
9235 3076 }
9236
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9237 {
9238
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9239 {
9240
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9241 return qe_invalid;
9242 943360 }
9243
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9244 {
9245
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9246 return qe_invalid;
9247 943360 }
9248
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9249 {
9250
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9251 return qe_invalid;
9252 943360 }
9253 5360 }
9254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9255 {
9256
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9257 return qe_invalid;
9258
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9259 return qe_invalid;
9260
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9261 return qe_invalid;
9262
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9263 return qe_invalid;
9264
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9265 return qe_invalid;
9266
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9267 return qe_invalid;
9268
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9269 return qe_invalid;
9270
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9271 return qe_invalid;
9272
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9273 return qe_invalid;
9274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9275 return qe_invalid;
9276
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9277 return qe_invalid;
9278 8380 }
9279
9280 8380 dword numffc = screen.numFFC();
9281
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9282 return qe_invalid;
9283
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9284 {
9285 245678 ffcdata const& tempffc = screen.ffcs[k];
9286
9287
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9288 return qe_invalid;
9289
9290
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9291 243364 continue;
9292
9293
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9294 return qe_invalid;
9295
9296
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9297 return qe_invalid;
9298
9299
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9300 return qe_invalid;
9301
9302
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9303 return qe_invalid;
9304
9305
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9306 return qe_invalid;
9307
9308
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9309 return qe_invalid;
9310
9311
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9312 return qe_invalid;
9313
9314
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9315 return qe_invalid;
9316
9317
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9318 return qe_invalid;
9319
9320
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9321 return qe_invalid;
9322
9323
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9324 return qe_invalid;
9325
9326
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9327 return qe_invalid;
9328
9329
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9330 return qe_invalid;
9331
9332
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9333 return qe_invalid;
9334
9335
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9336 return qe_invalid;
9337
9338
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9339 {
9340
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9341 return qe_invalid;
9342 18512 }
9343
9344
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9345 return qe_invalid;
9346 2314 }
9347
9348
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9349 return qe_invalid;
9350
9351
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9352 {
9353
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9354 return qe_invalid;
9355
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9356 return qe_invalid;
9357 6 }
9358
9359 8380 return qe_OK;
9360 12784 }
9361
9362 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9363 {
9364 9 dword section_id=ID_MAPS;
9365 9 dword section_version=V_MAPS;
9366 9 dword section_size = 0;
9367
9368 //section id
9369
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9370 {
9371 new_return(1);
9372 }
9373
9374 //section version info
9375
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9376 {
9377 new_return(2);
9378 }
9379
9380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9381 {
9382 new_return(3);
9383 }
9384
9385
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9386 {
9387 18 fake_pack_writing=(writecycle==0);
9388
9389 //section size
9390
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9391 {
9392 new_return(4);
9393 }
9394
9395 18 writesize=0;
9396
9397
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9398 {
9399 new_return(5);
9400 }
9401 18 map_infos.resize(map_count);
9402
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9403 {
9404 100 byte valid = 0;
9405
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9406 {
9407
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9408 break;
9409 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9410
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9411 {
9412 94 valid = 1;
9413 94 break;
9414 }
9415 1188 }
9416
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9417 {
9418 new_return(6);
9419 }
9420
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9421
9422 { //per-map info
9423 94 auto const& mapinf = map_infos[i];
9424
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9425 {
9426
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9427 new_return(7);
9428 564 }
9429
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9430 new_return(9);
9431
9432
9433
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9434 {
9435
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9436 {
9437
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9438 {
9439 new_return(8);
9440 }
9441 6016 }
9442 752 }
9443 }
9444
9445
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9446 12784 writemapscreen(f,i,j);
9447 94 }
9448
9449
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9450 {
9451 9 section_size=writesize;
9452 9 }
9453 18 }
9454
9455
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9456 {
9457 char ebuf[80];
9458 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9459 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9460 }
9461
9462 9 new_return(0);
9463 }
9464
9465 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9466 {
9467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9468 return 22;
9469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9470 return 22;
9471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9472 return 23;
9473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9474 return 34;
9475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9476 return 35;
9477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9478 return 36;
9479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9480 return 37;
9481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9482 return 38;
9483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9484 return 39;
9485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9486 return 40;
9487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9488 return 41;
9489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9490 return 42;
9491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9492 return 43;
9493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9494 return 44;
9495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9496 return 45;
9497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9498 return 46;
9499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9500 return 47;
9501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9502 return 48;
9503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9504 return 49;
9505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9506 return 50;
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9508 return 51;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9510 return 52;
9511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9512 return 53;
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9514 return 69;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9516 return 70;
9517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9518 return 71;
9519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9520 return 72;
9521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9522 return 76;
9523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9524 return 77;
9525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9526 return 89;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9528 return 90;
9529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9530 return 91;
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9532 return 92;
9533
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9535 return 93;
9536
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9537 return 94;
9538
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9539 return 95;
9540
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9541 return 96;
9542
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9543 return 97;
9544
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9545 return 98;
9546
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9547 return 99;
9548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9549 return 100;
9550
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9551 return 101;
9552
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9553 return 102;
9554
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9555 return 103;
9556
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9557 return 104;
9558
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9559 return 105;
9560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9561 return 106;
9562
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9563 return 107;
9564
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9565 return 108;
9566
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9567 return 109;
9568
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9569 return 110;
9570
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9571 return 111;
9572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9573 return 112;
9574
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9575 return 113;
9576
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9577 return 114;
9578
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9579 return 115;
9580
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9581 return 116;
9582
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9583 return 117;
9584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9585 return 118;
9586
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9587 return 119;
9588
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9589 return 120;
9590
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9591 return 121;
9592
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9593 return 122;
9594
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9595 return 123;
9596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9597 return 124;
9598
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9599 return 125;
9600
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9601 return 126;
9602 460 return 0;
9603 460 }
9604 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9605 {
9606 //Check what needs writing
9607 258906 word combo_has_flags = 0;
9608
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9609 {
9610
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9611
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9612 {
9613 3190 combo_has_flags |= CHAS_ATTRIB;
9614 3190 break;
9615 }
9616 2052960 }
9617
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9618 460 combo_has_flags |= CHAS_TRIG;
9619
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9620 298 combo_has_flags |= CHAS_FLAG;
9621
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9622
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9623
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9624 28174 combo_has_flags |= CHAS_ANIM;
9625
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9626 6 combo_has_flags |= CHAS_SCRIPT;
9627
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9628 {
9629
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9630 {
9631 combo_has_flags |= CHAS_SCRIPT;
9632 break;
9633 }
9634 2071200 }
9635
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9636
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9637 82514 combo_has_flags |= CHAS_BASIC;
9638
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9639
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9640
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9641
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9642
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9643
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9644
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9645 10 combo_has_flags |= CHAS_LIFT;
9646
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9647
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9648
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9649
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9650
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height)
9651 258906 combo_has_flags |= CHAS_GENERAL;
9652
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9653 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9654
9655
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9656 {
9657 return 50;
9658 }
9659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9660 //Write the combo
9661
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9662 {
9663
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9664 return 6;
9665
9666
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9667 return 7;
9668
9669
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9670 return 8;
9671
9672
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9673 return 9;
9674
9675
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9676 return 15;
9677
9678
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9679 return 10;
9680 82514 }
9681
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9682 {
9683 6 p_putcstr(tmp_cmb.label, f);
9684
9685
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9686 return 26;
9687
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9688
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9689 return 27;
9690 6 }
9691
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9692 {
9693
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9694 return 11;
9695
9696
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9697 return 12;
9698
9699
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9700 return 13;
9701
9702
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9703 return 14;
9704
9705
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9706 return 16;
9707
9708
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9709 return 18;
9710
9711
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9712 return 19;
9713 28174 }
9714
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9715 {
9716
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9717
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9718 return 20;
9719
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9720
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9721 return 25;
9722
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9723
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9724 return 32;
9725 3190 }
9726
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9727 {
9728
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9729 return 21;
9730
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9731 return 33;
9732 298 }
9733
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9734 {
9735
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9736
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9737 return 34;
9738
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9739 {
9740 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9741
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9742 460 }
9743
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9744 return 35;
9745 460 }
9746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9747 {
9748
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9749 return 54;
9750
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9751 return 55;
9752
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9753 return 56;
9754
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9755 return 57;
9756
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9757 return 58;
9758
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9759 return 59;
9760
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9761 return 60;
9762
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9763 return 61;
9764
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9765 return 62;
9766
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9767 return 63;
9768
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9769 return 64;
9770
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9771 return 65;
9772
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9773 return 66;
9774
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9775 return 67;
9776
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9777 return 68;
9778
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9779 return 78;
9780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9781 return ret;
9782 258906 }
9783
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9784 {
9785
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9786 return 73;
9787
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9788 return 74;
9789
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9790 return 75;
9791
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9792 return 79;
9793
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9794 return 80;
9795
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9796 return 81;
9797
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9798 return 82;
9799
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9800 return 83;
9801
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9802 return 84;
9803
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9804 return 85;
9805
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9806 return 86;
9807
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9808 return 87;
9809
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9810 return 88;
9811
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9812 return 89;
9813
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9814 return 90;
9815
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9816 return 91;
9817
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9818 return 92;
9819
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9820 return 93;
9821
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9822 return 94;
9823
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9824 return 95;
9825
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9826 return 96;
9827
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9828 return 97;
9829 2200 }
9830
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9831 {
9832 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9833 return ret;
9834 }
9835 258906 return 0;
9836 258906 }
9837
9838 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9839 {
9840 //these are here to bypass compiler warnings about unused arguments
9841 9 version=version;
9842 9 build=build;
9843
9844 word combos_used;
9845 9 dword section_id=ID_COMBOS;
9846 9 dword section_version=V_COMBOS;
9847 // dword section_size=0;
9848 9 combos_used = count_combos()-start_combo;
9849
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9850
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9851 9 dword section_size = 0;
9852
9853 //section id
9854
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9855 {
9856 new_return(1);
9857 }
9858
9859 //section version info
9860
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9861 {
9862 new_return(2);
9863 }
9864
9865
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9866 {
9867 new_return(3);
9868 }
9869
9870
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9871 {
9872 18 fake_pack_writing=(writecycle==0);
9873
9874 //section size
9875
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9876 {
9877 new_return(4);
9878 }
9879
9880 18 writesize=0;
9881
9882 //finally... section data
9883 18 combos_used=count_combos()-start_combo;
9884
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9885
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9886
9887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9888 {
9889 new_return(5);
9890 }
9891
9892 18 size_t end_combo = start_combo+combos_used;
9893
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9894 {
9895 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9896
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9897 258906 }
9898
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9899 {
9900 9 section_size=writesize;
9901 9 }
9902 18 }
9903
9904
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9905 {
9906 char ebuf[80];
9907 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9908 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9909 }
9910
9911 9 new_return(0);
9912 9 }
9913
9914 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9915 {
9916 //these are here to bypass compiler warnings about unused arguments
9917 9 version=version;
9918 9 build=build;
9919
9920 9 dword section_id=ID_COMBOALIASES;
9921 9 dword section_version=V_COMBOALIASES;
9922 9 dword section_size=0;
9923
9924 //section id
9925
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9926 {
9927 new_return(1);
9928 }
9929
9930 //section version info
9931
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9932 {
9933 new_return(2);
9934 }
9935
9936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9937 {
9938 new_return(3);
9939 }
9940
9941
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9942 {
9943 18 fake_pack_writing=(writecycle==0);
9944
9945 //section size
9946
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9947 {
9948 new_return(4);
9949 }
9950
9951 18 writesize=0;
9952
9953 //finally... section data
9954
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9955 {
9956
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9957 {
9958 new_return(5);
9959 }
9960
9961
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9962 {
9963 new_return(6);
9964 }
9965
9966 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9967
9968
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
9969 {
9970 new_return(7);
9971 }
9972
9973
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
9974 {
9975 new_return(8);
9976 }
9977
9978
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
9979 {
9980 new_return(9);
9981 }
9982
9983
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9984 {
9985
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
9986 {
9987 new_return(10);
9988 }
9989 149596 }
9990
9991
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9992 {
9993
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
9994 {
9995 new_return(11);
9996 }
9997 149596 }
9998 147456 }
9999
10000 //Combo pools!
10001 int16_t num_cpools;
10002
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10003 {
10004
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10005 {
10006 2 ++num_cpools;
10007 2 break;
10008 }
10009 147450 }
10010
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10011
10012
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10013 {
10014 new_return(12);
10015 }
10016
10017
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10018 {
10019 6 combo_pool const& pool = combo_pools[cp];
10020 6 int32_t num_combos = pool.combos.size();
10021
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10022 {
10023 new_return(13);
10024 }
10025
10026
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10027 {
10028 26 cpool_entry const& entry = pool.combos.at(q);
10029
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10030 {
10031 new_return(14);
10032 }
10033
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10034 {
10035 new_return(15);
10036 }
10037
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10038 {
10039 new_return(16);
10040 }
10041 26 }
10042 6 }
10043
10044 //Autocombos!
10045 int16_t num_cautos;
10046
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10047 {
10048
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10049 {
10050 ++num_cautos;
10051 break;
10052 }
10053 147456 }
10054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10055
10056
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10057 {
10058 new_return(17);
10059 }
10060
10061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10062 {
10063 combo_auto const& cauto = combo_autos[ca];
10064 if (!p_putc(cauto.getType(), f))
10065 {
10066 new_return(18);
10067 }
10068 if (!p_iputl(cauto.getIconDisplay(), f))
10069 {
10070 new_return(19);
10071 }
10072 if (!p_iputl(cauto.getEraseCombo(), f))
10073 {
10074 new_return(20);
10075 }
10076 if (!p_putc(cauto.getFlags(), f))
10077 {
10078 new_return(21);
10079 }
10080 if (!p_putc(cauto.getArg(), f))
10081 {
10082 new_return(22);
10083 }
10084 int32_t num_combos = cauto.combos.size();
10085 if (!p_iputl(num_combos, f))
10086 {
10087 new_return(23);
10088 }
10089
10090 for (auto q = 0; q < num_combos; ++q)
10091 {
10092 autocombo_entry const& entry = cauto.combos.at(q);
10093 if (!p_putc(entry.ctype, f))
10094 {
10095 new_return(24);
10096 }
10097 if (!p_iputl(entry.cid, f))
10098 {
10099 new_return(25);
10100 }
10101 }
10102 }
10103
10104
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10105 {
10106 9 section_size=writesize;
10107 9 }
10108 18 }
10109
10110
10111
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10112 {
10113 char ebuf[80];
10114 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10115 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10116 }
10117
10118 9 new_return(0);
10119 }
10120
10121 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10122 {
10123 //these are here to bypass compiler warnings about unused arguments
10124 9 version=version;
10125 9 build=build;
10126 9 start_cset=start_cset;
10127 9 max_csets=max_csets;
10128
10129 9 dword section_id=ID_CSETS;
10130 9 dword section_version=V_CSETS;
10131 9 int32_t palcycles = count_palcycles(&QMisc);
10132 // int32_t palcyccount = count_palcycles(&QMisc);
10133 9 dword section_size = 0;
10134
10135 //section id
10136
10137
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10138 {
10139 new_return(1);
10140 }
10141
10142 //section version info
10143
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10144 {
10145 new_return(2);
10146 }
10147
10148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10149 {
10150 new_return(3);
10151 }
10152
10153
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10154 {
10155 18 fake_pack_writing=(writecycle==0);
10156
10157 //section size
10158
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10159 {
10160 new_return(4);
10161 }
10162
10163 18 writesize=0;
10164
10165 //finally... section data
10166
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10167 {
10168 new_return(5);
10169 }
10170
10171
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10172 {
10173 new_return(6);
10174 }
10175
10176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10177 {
10178 new_return(15);
10179 }
10180
10181
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10182 {
10183
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10184 {
10185
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10186 {
10187 new_return(16);
10188 }
10189 1650 }
10190
10191
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10192 {
10193
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10194 {
10195 new_return(17);
10196 }
10197 1650 }
10198
10199
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10200 {
10201
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10202 {
10203 new_return(18);
10204 }
10205 1650 }
10206 550 }
10207
10208
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10209 {
10210 9 section_size=writesize;
10211 9 }
10212 18 }
10213
10214
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10215 {
10216 char ebuf[80];
10217 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10218 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10219 }
10220
10221 9 new_return(0);
10222 }
10223
10224 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10225 {
10226 //these are here to bypass compiler warnings about unused arguments
10227 9 version=version;
10228 9 build=build;
10229 9 start_msgstr=start_msgstr;
10230 9 max_msgstrs=max_msgstrs;
10231
10232 9 dword section_id=ID_STRINGS;
10233 9 dword section_version=V_STRINGS;
10234 9 dword section_size = 0;
10235
10236 //section id
10237
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10238 {
10239 new_return(1);
10240 }
10241
10242 //section version info
10243
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10244 {
10245 new_return(2);
10246 }
10247
10248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10249 {
10250 new_return(3);
10251 }
10252
10253
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10254 {
10255 18 fake_pack_writing=(writecycle==0);
10256
10257 //section size
10258
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10259 {
10260 new_return(4);
10261 }
10262
10263 18 writesize=0;
10264
10265 //finally... section data
10266
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10267 {
10268 return qe_invalid;
10269 }
10270
10271
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10272 {
10273 836 int32_t sz = MsgStrings[i].s.size();
10274
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10275
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10276 {
10277 return qe_invalid;
10278 }
10279
10280 836 char const* tmpstr = MsgStrings[i].s.c_str();
10281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10282 {
10283
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10284 {
10285 return qe_invalid;
10286 }
10287 836 }
10288
10289
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10290 {
10291 return qe_invalid;
10292 }
10293
10294
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10295 {
10296 return qe_invalid;
10297 }
10298
10299
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10300 {
10301 return qe_invalid;
10302 }
10303
10304
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10305 {
10306 return qe_invalid;
10307 }
10308
10309
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10310 {
10311 return qe_invalid;
10312 }
10313
10314
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10315 {
10316 return qe_invalid;
10317 }
10318
10319
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10320 {
10321 return qe_invalid;
10322 }
10323
10324
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10325 {
10326 return qe_invalid;
10327 }
10328
10329
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10330 {
10331 return qe_invalid;
10332 }
10333
10334
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10335 {
10336 return qe_invalid;
10337 }
10338
10339
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10340 {
10341 return qe_invalid;
10342 }
10343
10344
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10345 {
10346 return qe_invalid;
10347 }
10348
10349
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10350 {
10351
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10352 {
10353 return qe_invalid;
10354 }
10355 3344 }
10356
10357
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10358 {
10359 return qe_invalid;
10360 }
10361
10362
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10363 {
10364 return qe_invalid;
10365 }
10366
10367
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10368 {
10369 return qe_invalid;
10370 }
10371
10372
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10373 {
10374 return qe_invalid;
10375 }
10376
10377
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10378 {
10379 return qe_invalid;
10380 }
10381
10382
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10383 {
10384 return qe_invalid;
10385 }
10386
10387
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10388 {
10389 return qe_invalid;
10390 }
10391
10392
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10393 {
10394 return qe_invalid;
10395 }
10396
10397
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10398 {
10399 return qe_invalid;
10400 }
10401
10402
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10403 {
10404 return qe_invalid;
10405 }
10406
10407
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10408 {
10409 return qe_invalid;
10410 }
10411 836 }
10412
10413
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10414 {
10415 9 section_size=writesize;
10416 9 }
10417 18 }
10418
10419
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10420 {
10421 char ebuf[80];
10422 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10423 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10424 }
10425
10426 9 new_return(0);
10427 9 }
10428
10429 int32_t writestrings_text(PACKFILE *f)
10430 {
10431 std::map<int32_t, int32_t> msglistcache;
10432
10433 for(int32_t index = 1; index<msg_count; index++)
10434 {
10435 for(int32_t i=1; i<msg_count; i++)
10436 {
10437 if(MsgStrings[i].listpos==index)
10438 {
10439 msglistcache[index-1]=i;
10440 break;
10441 }
10442 }
10443 }
10444
10445 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10446 {
10447 fake_pack_writing=(writecycle==0);
10448 char ebuf[32];
10449
10450 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10451
10452 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10453 {
10454 return qe_invalid;
10455 }
10456
10457 for(int32_t i=1; i<msg_count; i++)
10458 {
10459 int32_t str = msglistcache[i-1];
10460
10461 if(!str)
10462 continue;
10463
10464 if(MsgStrings[str].nextstring != 0)
10465 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10466 else
10467 sprintf(ebuf,"\n\n___%d___\n", str);
10468
10469 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10470 {
10471 return qe_invalid;
10472 }
10473
10474 std::string text = MsgStrings[str].serialize();
10475 if (!pfwrite(text.c_str(), text.size(), f))
10476 {
10477 return qe_invalid;
10478 }
10479 }
10480 }
10481
10482 new_return(0);
10483 }
10484
10485 1 int32_t writestrings_tsv(PACKFILE *f)
10486 {
10487 1 std::stringstream ss;
10488
10489
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10490
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10491
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10492
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10493
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10494
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10495
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10496
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10497
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10498
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10499
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10500
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10501
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10502
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10503
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10504
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10505
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10506
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10507
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10508
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10509
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10510
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10511
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10512
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10515 };
10516
10517
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10518 {
10519
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10520
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10521 1 break;
10522
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10523 }
10524
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10525
10526 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10527
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10528
10529
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10530 {
10531 35 auto& msg = MsgStrings[i];
10532
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10533 {
10534
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10535
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10536
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10537 35 break;
10538
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10539
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10540
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10541 35 }
10542
10543
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10544
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10545 {
10546 return qe_invalid;
10547 }
10548
10549 1 new_return(0);
10550 1 }
10551
10552 std::string parse_to_legacy_msg_str_encoding(std::string const& s);
10553
10554 void parse_strings_tsv(std::string tsv)
10555 {
10556 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10557 { "message", [](auto& msg, auto& text){ msg.setFromLegacyEncoding(parse_to_legacy_msg_str_encoding(text)); } },
10558 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10559 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10560 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10561 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10562 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10563 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10564 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10565 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10566 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10567 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10568 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10569 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10570 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10571 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10572 { "margin", [&](auto& msg, auto& text){
10573 std::vector<std::string> strs;
10574 util::split(text, strs, ' ');
10575 if (strs.size() != 4)
10576 throw std::runtime_error("margin field must have 4 components");
10577 msg.margins[0] = std::stoi(strs[0]);
10578 msg.margins[1] = std::stoi(strs[1]);
10579 msg.margins[2] = std::stoi(strs[2]);
10580 msg.margins[3] = std::stoi(strs[3]);
10581 } },
10582 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10583 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10584 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10585 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10586 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10587 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10588 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10589 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10590 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10591 };
10592
10593 std::vector<std::string> rows;
10594 util::split(tsv, rows, '\n');
10595 if (rows.size())
10596 {
10597 std::string last = rows.back();
10598 util::trimstr(last);
10599 if (last.empty())
10600 rows.pop_back();
10601 }
10602 if (rows.size() <= 1)
10603 throw std::runtime_error("missing header row");
10604
10605 std::vector<std::string> columns;
10606 util::split(rows[0], columns, '\t');
10607 for (auto name : columns)
10608 {
10609 if (!fields.contains(name))
10610 throw std::runtime_error(fmt::format("invalid field: {}", name));
10611 }
10612
10613 int start_index = 1;
10614 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10615 start_index += 1;
10616
10617 int num_strings = rows.size() - start_index + 1;
10618 if (num_strings > MAXMSGS-1)
10619 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10620
10621 std::vector<MsgStr> msgs;
10622 msgs.reserve(num_strings);
10623 for (int i = start_index; i < rows.size(); i++)
10624 {
10625 std::vector<std::string> strs;
10626 util::split(rows[i], strs, '\t');
10627 if (strs.size() != columns.size())
10628 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10629
10630 int j = 0;
10631 auto& msg = msgs.emplace_back();
10632 for (auto& name : columns)
10633 {
10634 auto& fn = fields[name];
10635 try
10636 {
10637 fn(msg, strs[j++]);
10638 }
10639 catch (std::exception& ex)
10640 {
10641 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10642 }
10643 }
10644 }
10645
10646 init_msgstrings(0, msgs.size());
10647 for (int i = 0; i < msgs.size(); i++)
10648 MsgStrings[i + 1] = msgs[i];
10649 msg_count = msgs.size() + 1;
10650 msglistcache.clear();
10651 }
10652
10653 bool isblanktile(tiledata *buf, int32_t i);
10654 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10655 {
10656 //these are here to bypass compiler warnings about unused arguments
10657 9 version=version;
10658 9 build=build;
10659
10660 int32_t tiles_used;
10661 9 dword section_id=ID_TILES;
10662 9 dword section_version=V_TILES;
10663 9 al_trace("Counting tiles used\n");
10664 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10667 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10668 9 dword section_size = 0;
10669
10670 //section id
10671
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10672 {
10673 new_return(1);
10674 }
10675
10676 //section version info
10677
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10678 {
10679 new_return(2);
10680 }
10681
10682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10683 {
10684 new_return(3);
10685 }
10686
10687
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10688 {
10689 18 fake_pack_writing=(writecycle==0);
10690
10691 //section size
10692
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10693 {
10694 new_return(4);
10695 }
10696
10697 18 writesize=0;
10698
10699 //finally... section data
10700 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10701
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10702
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10703
10704
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10705 {
10706 new_return(5);
10707 }
10708
10709
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10710 {
10711
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10712 {
10713
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10714 new_return(8);
10715 365770 }
10716 else
10717 {
10718 330614 int format = newtilebuf[start_tile+i].format;
10719
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10720 {
10721 new_return(6);
10722 }
10723
10724
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10725 {
10726 byte temp_tile[128];
10727 327742 byte *di = temp_tile;
10728 327742 byte *src = newtilebuf[start_tile+i].data;
10729
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10730 {
10731 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10732 41950976 ++di;
10733 41950976 }
10734
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10735 {
10736 new_return(7);
10737 }
10738 327742 }
10739
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10740 {
10741 new_return(7);
10742 }
10743 }
10744 696384 }
10745
10746
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10747 {
10748 9 section_size=writesize;
10749 9 }
10750 18 }
10751
10752
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10753 {
10754 char ebuf[80];
10755 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10756 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10757 }
10758
10759 9 new_return(0);
10760 }
10761
10762 /* MIDI Format
10763 section_id LONG
10764 section_version WORD
10765 section_cversion WORD
10766 section_size LONG
10767 midi_flags 32 Byte ? BITFIELD[252]
10768
10769 [
10770 title 36
10771 start 4
10772 loop_start 4
10773 loop_end 4
10774 loop 2
10775 volume 2
10776 midi *
10777 ]
10778
10779 */
10780
10781 9 int32_t writemidis(PACKFILE *f)
10782 {
10783 9 dword section_id=ID_MIDIS;
10784 9 dword section_version=V_MIDIS;
10785 9 dword section_size = 0;
10786
10787 //section id
10788
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10789 {
10790 new_return(1);
10791 }
10792
10793 //section version info
10794
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10795 {
10796 new_return(2);
10797 }
10798
10799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10800 {
10801 new_return(3);
10802 }
10803
10804
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10805 {
10806 18 fake_pack_writing=(writecycle==0);
10807
10808 //section size
10809
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10810 {
10811 new_return(4);
10812 }
10813
10814 18 writesize=0;
10815
10816 //finally... section data
10817
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10818 {
10819 new_return(5);
10820 }
10821
10822
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10823 {
10824
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10825 {
10826
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10827 {
10828 new_return(6);
10829 }
10830
10831
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10832 {
10833 new_return(7);
10834 }
10835
10836
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10837 {
10838 new_return(8);
10839 }
10840
10841
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10842 {
10843 new_return(9);
10844 }
10845
10846
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10847 {
10848 new_return(10);
10849 }
10850
10851
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10852 {
10853 new_return(11);
10854 }
10855
10856
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10857 {
10858 new_return(12);
10859 }
10860
10861 130 byte format = MFORMAT_MIDI;
10862
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10863 {
10864 new_return(13);
10865 }
10866
10867
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10868 130 }
10869 4536 }
10870
10871
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10872 {
10873 9 section_size=writesize;
10874 9 }
10875 18 }
10876
10877
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10878 {
10879 char ebuf[80];
10880 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10881 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10882 }
10883
10884 9 new_return(0);
10885 }
10886
10887 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10888 {
10889 9 dword section_id=ID_CHEATS;
10890 9 dword section_version=V_CHEATS;
10891 9 dword section_size = 0;
10892
10893 //section id
10894
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10895 {
10896 new_return(1);
10897 }
10898
10899 //section version info
10900
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10901 {
10902 new_return(2);
10903 }
10904
10905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10906 {
10907 new_return(3);
10908 }
10909
10910
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10911 {
10912 18 fake_pack_writing=(writecycle==0);
10913
10914 //section size
10915
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10916 {
10917 new_return(4);
10918 }
10919
10920 18 writesize=0;
10921
10922 //finally... section data
10923
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10924 {
10925 new_return(5);
10926 }
10927
10928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10929 {
10930
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10931 {
10932 new_return(6);
10933 }
10934
10935
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10936 {
10937 new_return(7);
10938 }
10939 18 }
10940
10941
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10942 {
10943 9 section_size=writesize;
10944 9 }
10945 18 }
10946
10947
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10948 {
10949 char ebuf[80];
10950 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10951 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10952 }
10953
10954 9 new_return(0);
10955 }
10956
10957 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10958 {
10959 //these are here to bypass compiler warnings about unused arguments
10960 9 Header=Header;
10961
10962 9 dword section_id=ID_GUYS;
10963 9 dword section_version=V_GUYS;
10964 9 dword section_size=0;
10965
10966 //section id
10967
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10968 {
10969 new_return(1);
10970 }
10971
10972 //section version info
10973
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10974 {
10975 new_return(2);
10976 }
10977
10978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10979 {
10980 new_return(3);
10981 }
10982
10983
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10984 {
10985 18 fake_pack_writing=(writecycle==0);
10986
10987 //section size
10988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10989 {
10990 new_return(4);
10991 }
10992
10993 18 writesize=0;
10994
10995 //finally... section data
10996
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
10997 {
10998
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
10999 {
11000 new_return(5);
11001 }
11002 9216 }
11003
11004
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11005 {
11006 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11007 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11008
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11009 {
11010 new_return(6);
11011 }
11012
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11013 {
11014 new_return(7);
11015 }
11016
11017
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11018 {
11019 new_return(8);
11020 }
11021
11022
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11023 {
11024 new_return(9);
11025 }
11026
11027
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11028 {
11029 new_return(10);
11030 }
11031
11032
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11033 {
11034 new_return(11);
11035 }
11036
11037
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11038 {
11039 new_return(12);
11040 }
11041
11042
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11043 {
11044 new_return(13);
11045 }
11046
11047
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11048 {
11049 new_return(14);
11050 }
11051
11052
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11053 {
11054 new_return(15);
11055 }
11056
11057
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11058 {
11059 new_return(16);
11060 }
11061
11062
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11063 {
11064 new_return(17);
11065 }
11066
11067
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11068 {
11069 new_return(18);
11070 }
11071
11072
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11073 {
11074 new_return(19);
11075 }
11076
11077
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11078 {
11079 new_return(20);
11080 }
11081
11082
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11083 {
11084 new_return(21);
11085 }
11086
11087
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11088 {
11089 new_return(22);
11090 }
11091
11092
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11093 {
11094 new_return(23);
11095 }
11096
11097
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11098 {
11099 new_return(24);
11100 }
11101
11102
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11103 {
11104 new_return(25);
11105 }
11106
11107
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11108 {
11109 new_return(26);
11110 }
11111
11112
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11113 {
11114 new_return(27);
11115 }
11116
11117
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11118 {
11119 new_return(28);
11120 }
11121
11122
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11123 {
11124 new_return(29);
11125 }
11126
11127
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11128 {
11129 new_return(30);
11130 }
11131
11132
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11133 {
11134 new_return(31);
11135 }
11136
11137
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11138 {
11139 new_return(32);
11140 }
11141
11142
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11143 {
11144 new_return(33);
11145 }
11146
11147
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11148 {
11149 new_return(34);
11150 }
11151
11152
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11153 {
11154 new_return(35);
11155 }
11156
11157
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11158 {
11159 new_return(36);
11160 }
11161
11162
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11163 {
11164 new_return(37);
11165 }
11166
11167
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11168 {
11169 new_return(38);
11170 }
11171
11172
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11173 {
11174 new_return(39);
11175 }
11176
11177
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11178 {
11179 new_return(40);
11180 }
11181
11182
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11183 {
11184 new_return(41);
11185 }
11186
11187
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11188 {
11189 new_return(42);
11190 }
11191
11192
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11193 {
11194 new_return(43);
11195 }
11196
11197
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11198 {
11199 new_return(44);
11200 }
11201
11202
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11203 {
11204 new_return(45);
11205 }
11206
11207
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11208 {
11209
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11210 {
11211 new_return(46);
11212 }
11213 175104 }
11214
11215
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11216 {
11217 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11219 //Force SFX_HIT here.
11220
11221 2048 }
11222
11223
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11224 {
11225 new_return(47);
11226 }
11227
11228
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11229 {
11230 new_return(48);
11231 }
11232
11233
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11234 {
11235 new_return(49);
11236 }
11237
11238
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11239 {
11240 new_return(50);
11241 }
11242
11243 //New 2.6 defences
11244
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11245 {
11246
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11247 {
11248 new_return(51);
11249 }
11250 202752 }
11251
11252 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11253
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11254 {
11255 new_return(52);
11256 }
11257
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11258 {
11259 new_return(53);
11260 }
11261
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11262 {
11263 new_return(54);
11264 }
11265
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11266 {
11267 new_return(55);
11268 }
11269
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11270 {
11271 new_return(56);
11272 }
11273 // These are not fixed types, but ints, so they are safe to use here.
11274
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11275 {
11276 new_return(57);
11277 }
11278
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11279 {
11280 new_return(58);
11281 }
11282
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11283 {
11284 new_return(59);
11285 }
11286
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11287 {
11288 new_return(60);
11289 }
11290
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11291 {
11292 new_return(61);
11293 }
11294
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11295 {
11296 new_return(62);
11297 }
11298
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11299 {
11300 new_return(63);
11301 }
11302
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11303 {
11304 new_return(64);
11305 }
11306
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11307 {
11308 new_return(65);
11309 }
11310
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11311 {
11312 new_return(66);
11313 }
11314
11315
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11316 {
11317
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11318 {
11319 new_return(67);
11320 }
11321 92160 }
11322
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11323 {
11324 new_return(68);
11325 }
11326 //misc 16->31
11327
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11328 {
11329 new_return(69);
11330 }
11331
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11332 {
11333 new_return(70);
11334 }
11335
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11336 {
11337 new_return(71);
11338 }
11339
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11340 {
11341 new_return(72);
11342 }
11343
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11344 {
11345 new_return(73);
11346 }
11347
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11348 {
11349 new_return(74);
11350 }
11351
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11352 {
11353 new_return(75);
11354 }
11355
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11356 {
11357 new_return(76);
11358 }
11359
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11360 {
11361 new_return(77);
11362 }
11363
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11364 {
11365 new_return(78);
11366 }
11367
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11368 {
11369 new_return(79);
11370 }
11371
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11372 {
11373 new_return(80);
11374 }
11375
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11376 {
11377 new_return(81);
11378 }
11379
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11380 {
11381 new_return(82);
11382 }
11383
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11384 {
11385 new_return(83);
11386 }
11387
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11388 {
11389 new_return(84);
11390 }
11391
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11392 {
11393 new_return(85);
11394 }
11395
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11396 {
11397
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11398 {
11399 new_return(86);
11400 }
11401 294912 }
11402
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11403 {
11404
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11405 {
11406 new_return(87);
11407 }
11408 294912 }
11409
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11410 {
11411 new_return(88);
11412 }
11413
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11414 {
11415
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11416 {
11417 new_return(89);
11418 }
11419 73728 }
11420
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11421 {
11422
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11423 {
11424 new_return(90);
11425 }
11426 18432 }
11427
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11428 {
11429 new_return(91);
11430 }
11431 //somehow forgot these in the older builds -Z
11432
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11433 {
11434 new_return(92);
11435 }
11436
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11437 {
11438 new_return(93);
11439 }
11440
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11441 {
11442 new_return(94);
11443 }
11444
11445 //Enemy Editor InitD[] labels
11446
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11447 {
11448
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11449 {
11450
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11451 {
11452 new_return(95);
11453 }
11454 4792320 }
11455 73728 }
11456
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11457 new_return(99);
11458
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11459 new_return(100);
11460
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11461 new_return(101);
11462
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11463 new_return(102);
11464
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11465 new_return(103);
11466
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11467 return ret;
11468 9216 }
11469
11470
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11471 {
11472 9 section_size=writesize;
11473 9 }
11474 18 }
11475
11476
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11477 {
11478 char ebuf[80];
11479 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11480 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11481 }
11482
11483 9 new_return(0);
11484 9 }
11485
11486 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11487 {
11488 //these are here to bypass compiler warnings about unused arguments
11489 9 Header=Header;
11490
11491 9 dword section_id=ID_HEROSPRITES;
11492 9 dword section_version=V_HEROSPRITES;
11493 9 dword section_size=0;
11494
11495 //section id
11496
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11497 {
11498 new_return(1);
11499 }
11500
11501 //section version info
11502
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11503 {
11504 new_return(2);
11505 }
11506
11507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11508 {
11509 new_return(3);
11510 }
11511
11512
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11513 {
11514 18 fake_pack_writing=(writecycle==0);
11515
11516 //section size
11517
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11518 {
11519 new_return(4);
11520 }
11521
11522 18 writesize=0;
11523
11524 //finally... section data
11525
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11526 {
11527
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11528 {
11529 new_return(5);
11530 }
11531
11532
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11533 {
11534 new_return(5);
11535 }
11536
11537
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11538 {
11539 new_return(5);
11540 }
11541 72 }
11542
11543
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11544 {
11545
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11546 {
11547 new_return(6);
11548 }
11549
11550
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11551 {
11552 new_return(6);
11553 }
11554
11555
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11556 {
11557 new_return(6);
11558 }
11559 72 }
11560
11561
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11562 {
11563
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11564 {
11565 new_return(7);
11566 }
11567
11568
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11569 {
11570 new_return(7);
11571 }
11572
11573
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11574 {
11575 new_return(7);
11576 }
11577 72 }
11578
11579
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11580 {
11581
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11582 {
11583 new_return(8);
11584 }
11585
11586
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11587 {
11588 new_return(8);
11589 }
11590
11591
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11592 {
11593 new_return(8);
11594 }
11595 72 }
11596
11597
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11598 {
11599
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11600 {
11601 new_return(8);
11602 }
11603
11604
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11605 {
11606 new_return(8);
11607 }
11608
11609
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11610 {
11611 new_return(8);
11612 }
11613 72 }
11614
11615
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11616 {
11617
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11618 {
11619 new_return(9);
11620 }
11621
11622
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11623 {
11624 new_return(9);
11625 }
11626
11627
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11628 {
11629 new_return(9);
11630 }
11631 72 }
11632
11633
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11634 {
11635
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11636 {
11637 new_return(10);
11638 }
11639
11640
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11641 {
11642 new_return(10);
11643 }
11644
11645
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11646 {
11647 new_return(10);
11648 }
11649 72 }
11650
11651
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11652 {
11653 new_return(11);
11654 }
11655
11656
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11657 {
11658 new_return(11);
11659 }
11660
11661
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11662 {
11663 new_return(11);
11664 }
11665
11666
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11667 {
11668
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11669 {
11670
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11671 {
11672 new_return(12);
11673 }
11674
11675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11676 {
11677 new_return(12);
11678 }
11679
11680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11681 {
11682 new_return(12);
11683 }
11684 108 }
11685 36 }
11686
11687
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11688 {
11689
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11690 {
11691 new_return(13);
11692 }
11693
11694
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11695 {
11696 new_return(13);
11697 }
11698
11699
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11700 {
11701 new_return(13);
11702 }
11703 72 }
11704
11705
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11706 {
11707
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11708 {
11709 new_return(13);
11710 }
11711
11712
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11713 {
11714 new_return(13);
11715 }
11716
11717
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11718 {
11719 new_return(13);
11720 }
11721 72 }
11722
11723
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11724 {
11725 new_return(14);
11726 }
11727
11728 //{ V_HEROSPRITES >= 7
11729
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11730 {
11731
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11732 new_return(15);
11733
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11734 new_return(15);
11735
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11736 new_return(15);
11737 72 }
11738
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11739 {
11740
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11741 new_return(15);
11742
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11743 new_return(15);
11744
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11745 new_return(15);
11746 72 }
11747
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11748 {
11749
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11750 new_return(15);
11751
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11752 new_return(15);
11753
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11754 new_return(15);
11755 72 }
11756
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11757 {
11758
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11759 new_return(15);
11760
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11761 new_return(15);
11762
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11763 new_return(15);
11764 72 }
11765
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11766 {
11767
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11768 new_return(15);
11769
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11770 new_return(15);
11771
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11772 new_return(15);
11773 72 }
11774
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11775 {
11776
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11777 new_return(15);
11778
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11779 new_return(15);
11780
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11781 new_return(15);
11782 72 }
11783
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11784 {
11785
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11786 new_return(15);
11787
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11788 new_return(15);
11789
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11790 new_return(15);
11791 72 }
11792
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11793 {
11794
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11795 new_return(15);
11796
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11797 new_return(15);
11798
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11799 new_return(15);
11800 72 }
11801
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11802 {
11803
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11804 new_return(15);
11805
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11806 new_return(15);
11807
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11808 new_return(15);
11809
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11810 new_return(15);
11811 72 }
11812
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11813 {
11814
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11815 new_return(15);
11816
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11817 new_return(15);
11818
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11819 new_return(15);
11820 72 }
11821
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11822 {
11823
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11824 new_return(15);
11825
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11826 new_return(15);
11827
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11828 new_return(15);
11829 72 }
11830
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11831 {
11832
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11833 new_return(15);
11834
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11835 new_return(15);
11836
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11837 new_return(15);
11838 72 }
11839
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11840 {
11841
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11842 new_return(15);
11843
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11844 new_return(15);
11845
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11846 new_return(15);
11847 72 }
11848
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11849 {
11850
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11851 new_return(15);
11852
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11853 new_return(15);
11854
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11855 new_return(15);
11856 72 }
11857
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11858 {
11859
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11860 new_return(15);
11861
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11862 new_return(15);
11863
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11864 new_return(15);
11865 72 }
11866
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11867 {
11868
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11869 new_return(15);
11870
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11871 new_return(15);
11872
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11873 new_return(15);
11874 72 }
11875
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11876 {
11877
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11878 new_return(15);
11879
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11880 new_return(15);
11881
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11882 new_return(15);
11883 72 }
11884
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11885 {
11886
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11887 new_return(15);
11888
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11889 new_return(15);
11890
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11891 new_return(15);
11892 72 }
11893
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11894 {
11895
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11896 new_return(15);
11897
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11898 new_return(15);
11899
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11900 new_return(15);
11901 72 }
11902
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11903 {
11904
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11905 new_return(15);
11906
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11907 new_return(15);
11908
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11909 new_return(15);
11910 72 }
11911
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11912 {
11913
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11914 new_return(15);
11915
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11916 new_return(15);
11917
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11918 new_return(15);
11919 72 }
11920
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11921 {
11922
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11923 new_return(15);
11924
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11925 new_return(15);
11926
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11927 new_return(15);
11928 72 }
11929
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11930 {
11931
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11932 new_return(15);
11933
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11934 new_return(15);
11935
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11936 new_return(15);
11937 72 }
11938
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11939 {
11940
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11941 new_return(15);
11942
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11943 new_return(15);
11944
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11945 new_return(15);
11946 54 }
11947
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11948 {
11949
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11950 new_return(16);
11951
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11952 new_return(16);
11953
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11954 new_return(16);
11955 72 }
11956
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11957 {
11958
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11959 new_return(17);
11960
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11961 new_return(17);
11962
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
11963 new_return(17);
11964 72 }
11965
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11966 {
11967
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
11968 new_return(17);
11969
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
11970 new_return(17);
11971
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
11972 new_return(17);
11973 72 }
11974
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11975 {
11976
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
11977 new_return(17);
11978
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
11979 new_return(17);
11980
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
11981 new_return(17);
11982 72 }
11983
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11984 {
11985
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
11986 new_return(18);
11987
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
11988 new_return(18);
11989
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
11990 new_return(18);
11991 72 }
11992
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11993 {
11994
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
11995 new_return(19);
11996 72 }
11997
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
11998 {
11999
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12000 new_return(20);
12001
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12002 new_return(20);
12003
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12004 new_return(20);
12005 54 }
12006
12007
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12008 {
12009 new_return(21);
12010 }
12011
12012
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12013 {
12014 new_return(21);
12015 }
12016
12017
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12018 {
12019 new_return(21);
12020 }
12021
12022
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12023 {
12024
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12025 new_return(22);
12026
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12027 new_return(22);
12028
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12029 new_return(22);
12030 72 }
12031
12032
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12033 {
12034
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12035 {
12036 new_return(23);
12037 }
12038
12039
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12040 {
12041 new_return(23);
12042 }
12043
12044
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12045 {
12046 new_return(23);
12047 }
12048 72 }
12049
12050
12051
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12052 {
12053
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12054 new_return(15);
12055 2628 }
12056 //}
12057
12058
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12059 {
12060 9 section_size=writesize;
12061 9 }
12062 18 }
12063
12064 //More data will come here
12065
12066
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12067 {
12068 char ebuf[80];
12069 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12070 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12071 }
12072
12073 9 new_return(0);
12074 }
12075
12076 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12077 {
12078 9 dword section_id=ID_SUBSCREEN;
12079 9 dword section_version=V_SUBSCREEN;
12080 9 dword section_size=0;
12081
12082 //section id
12083
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12084 {
12085 new_return(1);
12086 }
12087
12088 //section version info
12089
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12090 {
12091 new_return(2);
12092 }
12093
12094
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12095 {
12096 new_return(3);
12097 }
12098
12099
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12100 {
12101 18 fake_pack_writing=(writecycle==0);
12102
12103 //section size
12104
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12105 {
12106 new_return(4);
12107 }
12108
12109 18 writesize=0;
12110
12111 18 byte sz = subscreens_active.size();
12112
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12113 new_return(5);
12114
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12115 {
12116 86 int32_t ret = subscreens_active[i].write(f);
12117 86 fake_pack_writing=(writecycle==0);
12118
12119
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12120 new_return(ret);
12121 86 }
12122
12123 18 sz = subscreens_passive.size();
12124
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12125 new_return(5);
12126
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12127 {
12128 64 int32_t ret = subscreens_passive[i].write(f);
12129 64 fake_pack_writing=(writecycle==0);
12130
12131
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12132 new_return(ret);
12133 64 }
12134
12135 18 sz = subscreens_overlay.size();
12136
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12137 new_return(5);
12138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12139 {
12140 int32_t ret = subscreens_overlay[i].write(f);
12141 fake_pack_writing=(writecycle==0);
12142
12143 if(ret!=0)
12144 new_return(ret);
12145 }
12146
12147
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12148 {
12149 9 section_size=writesize;
12150 9 }
12151 18 }
12152
12153
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12154 {
12155 char ebuf[80];
12156 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12157 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12158 }
12159
12160 9 new_return(0);
12161 9 }
12162
12163 extern script_data *ffscripts[NUMSCRIPTFFC];
12164 extern script_data *itemscripts[NUMSCRIPTITEM];
12165 extern script_data *guyscripts[NUMSCRIPTGUYS];
12166 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12167 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12168 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12169 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12170 extern script_data *playerscripts[NUMSCRIPTHERO];
12171 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12172 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12173 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12174 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12175 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12176
12177 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12178 {
12179
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12180 3 return writeffscript_old(f, Header);
12181
12182 6 dword section_id = ID_FFSCRIPT;
12183 6 dword section_version = V_FFSCRIPT;
12184 6 dword section_size = 0;
12185 6 dword zasmmeta_version = METADATA_V;
12186 6 byte numscripts = 0;
12187 6 numscripts = numscripts; //to avoid unused variables warnings
12188
12189 //section id
12190
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12191 {
12192 new_return(1);
12193 }
12194
12195 //section version info
12196
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12197 {
12198 new_return(2);
12199 }
12200
12201
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12202 {
12203 new_return(3);
12204 }
12205
12206
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12207 {
12208 new_return(4);
12209 }
12210
12211
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12212 {
12213 12 fake_pack_writing=(writecycle==0);
12214
12215 //section size
12216
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12217 {
12218 new_return(5);
12219 }
12220
12221 12 writesize=0;
12222
12223 12 write_quest_zasm(f);
12224
12225
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12226 {
12227 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12228
12229
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12230 {
12231 new_return(ret);
12232 }
12233 6144 }
12234
12235
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12236 {
12237 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12238
12239
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12240 {
12241 new_return(ret);
12242 }
12243 3072 }
12244
12245
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12246 {
12247 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12248
12249
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12250 {
12251 new_return(ret);
12252 }
12253 3072 }
12254
12255
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12256
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12257 {
12258 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12259
12260
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12261 {
12262 new_return(ret);
12263 }
12264 3072 }
12265
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12266
12267
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12268 {
12269 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12270
12271
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12272 {
12273 new_return(ret);
12274 }
12275 3072 }
12276
12277
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12278 {
12279 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12280
12281
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12282 {
12283 new_return(ret);
12284 }
12285 96 }
12286
12287
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12288 {
12289 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12290
12291
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12292 {
12293 new_return(ret);
12294 }
12295 60 }
12296
12297
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12298 {
12299 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12300
12301
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12302 {
12303 new_return(ret);
12304 }
12305 3072 }
12306
12307
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12308 {
12309 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12310
12311
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12312 {
12313 new_return(ret);
12314 }
12315 3072 }
12316
12317
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12318 {
12319 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12320
12321
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12322 {
12323 new_return(ret);
12324 }
12325 3072 }
12326
12327
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12328 {
12329 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12330
12331
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12332 {
12333 new_return(ret);
12334 }
12335 3072 }
12336
12337
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12338 {
12339 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12340
12341
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12342 {
12343 new_return(ret);
12344 }
12345 6144 }
12346
12347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12348 {
12349 new_return(2000);
12350 }
12351
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12352 {
12353 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12354
12355
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12356 {
12357 new_return(ret);
12358 }
12359 6144 }
12360
12361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12362 {
12363 new_return(2001);
12364 }
12365
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12366 {
12367 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12368
12369
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12370 {
12371 new_return(ret);
12372 }
12373 3072 }
12374
12375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12376 {
12377 new_return(2001);
12378 }
12379
12380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12381 {
12382 new_return(2002);
12383 }
12384
12385 12 word numffcbindings=0;
12386
12387
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12388 {
12389
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12390 {
12391 158 numffcbindings++;
12392 158 }
12393 6132 }
12394
12395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12396 {
12397 new_return(2003);
12398 }
12399
12400
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12401 {
12402
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12403 {
12404
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12405 {
12406 new_return(2004);
12407 }
12408
12409
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12410 {
12411 new_return(2005);
12412 }
12413
12414
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12415 {
12416 new_return(2006);
12417 }
12418 158 }
12419 6132 }
12420
12421 12 word numglobalbindings=0;
12422
12423
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12424 {
12425
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12426 {
12427 22 numglobalbindings++;
12428 22 }
12429 96 }
12430
12431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12432 {
12433 new_return(2007);
12434 }
12435
12436
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12437 {
12438
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12439 {
12440
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12441 {
12442 new_return(2008);
12443 }
12444
12445
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12446 {
12447 new_return(2009);
12448 }
12449
12450
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12451 {
12452 new_return(2010);
12453 }
12454 22 }
12455 96 }
12456
12457 12 word numitembindings=0;
12458
12459
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12460 {
12461
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12462 {
12463 26 numitembindings++;
12464 26 }
12465 3060 }
12466
12467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12468 {
12469 new_return(2011);
12470 }
12471
12472
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12473 {
12474
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12475 {
12476
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12477 {
12478 new_return(2012);
12479 }
12480
12481
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12482 {
12483 new_return(2013);
12484 }
12485
12486
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12487 {
12488 new_return(2014);
12489 }
12490 26 }
12491 3060 }
12492
12493 //new script types
12494 //npc scripts
12495 12 word numnpcbindings=0;
12496
12497
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12498 {
12499
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12500 {
12501 numnpcbindings++;
12502 }
12503 3060 }
12504
12505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12506 {
12507 new_return(2015);
12508 }
12509
12510
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12511 {
12512
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12513 {
12514 if(!p_iputw(it->first,f))
12515 {
12516 new_return(2016);
12517 }
12518
12519 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12520 {
12521 new_return(2017);
12522 }
12523
12524 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12525 {
12526 new_return(2018);
12527 }
12528 }
12529 3060 }
12530
12531 //lweapon
12532
12533 12 word numlwpnbindings=0;
12534
12535
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12536 {
12537
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12538 {
12539 2 numlwpnbindings++;
12540 2 }
12541 3060 }
12542
12543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12544 {
12545 new_return(2019);
12546 }
12547
12548
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12549 {
12550
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12551 {
12552
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12553 {
12554 new_return(2020);
12555 }
12556
12557
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12558 {
12559 new_return(2021);
12560 }
12561
12562
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12563 {
12564 new_return(2022);
12565 }
12566 2 }
12567 3060 }
12568
12569 //////
12570
12571 //eweapon
12572
12573
12574 12 word numewpnbindings=0;
12575
12576
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12577 {
12578
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12579 {
12580 numewpnbindings++;
12581 }
12582 3060 }
12583
12584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12585 {
12586 new_return(2023);
12587 }
12588
12589
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12590 {
12591
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12592 {
12593 if(!p_iputw(it->first,f))
12594 {
12595 new_return(2024);
12596 }
12597
12598 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12599 {
12600 new_return(2025);
12601 }
12602
12603 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12604 {
12605 new_return(2026);
12606 }
12607 }
12608 3060 }
12609
12610 //player scripts
12611 12 word numherobindings=0;
12612
12613
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12614 {
12615
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12616 {
12617 numherobindings++;
12618 }
12619 48 }
12620
12621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12622 {
12623 new_return(2027);
12624 }
12625
12626
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12627 {
12628
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12629 {
12630 if(!p_iputw(it->first,f))
12631 {
12632 new_return(2028);
12633 }
12634
12635 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12636 {
12637 new_return(2029);
12638 }
12639
12640 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12641 {
12642 new_return(2030);
12643 }
12644 }
12645 48 }
12646
12647 //dmap scripts
12648 12 word numdmapbindings=0;
12649
12650
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12651 {
12652
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12653 {
12654 10 numdmapbindings++;
12655 10 }
12656 3060 }
12657
12658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12659 {
12660 new_return(2031);
12661 }
12662
12663
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12664 {
12665
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12666 {
12667
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12668 {
12669 new_return(2032);
12670 }
12671
12672
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12673 {
12674 new_return(2033);
12675 }
12676
12677
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12678 {
12679 new_return(2034);
12680 }
12681 10 }
12682 3060 }
12683
12684 //screen scripts
12685 12 word numscreenbindings=0;
12686
12687
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12688 {
12689
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12690 {
12691 4 numscreenbindings++;
12692 4 }
12693 3060 }
12694
12695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12696 {
12697 new_return(2035);
12698 }
12699
12700
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12701 {
12702
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12703 {
12704
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12705 {
12706 new_return(2036);
12707 }
12708
12709
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12710 {
12711 new_return(2037);
12712 }
12713
12714
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12715 {
12716 new_return(2038);
12717 }
12718 4 }
12719 3060 }
12720 //item sprite scripts
12721 12 word numitemspritebindings=0;
12722
12723
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12724 {
12725
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12726 {
12727 numitemspritebindings++;
12728 }
12729 3060 }
12730
12731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12732 {
12733 new_return(2039);
12734 }
12735
12736
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12737 {
12738
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12739 {
12740 if(!p_iputw(it->first,f))
12741 {
12742 new_return(2040);
12743 }
12744
12745 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12746 {
12747 new_return(2041);
12748 }
12749
12750 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12751 {
12752 new_return(2042);
12753 }
12754 }
12755 3060 }
12756
12757 //combo scripts
12758 12 word numcombobindings=0;
12759
12760
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12761 {
12762
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12763 {
12764 numcombobindings++;
12765 }
12766 6132 }
12767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12768 {
12769 new_return(2043);
12770 }
12771
12772
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12773 {
12774
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12775 {
12776 if(!p_iputw(it->first,f))
12777 {
12778 new_return(2044);
12779 }
12780
12781 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12782 {
12783 new_return(2045);
12784 }
12785
12786 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12787 {
12788 new_return(2046);
12789 }
12790 }
12791 6132 }
12792 //subscreen scripts
12793 12 word numgenericbindings=0;
12794
12795
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12796 {
12797
2/2
✓ Branch 0 taken 6092 times.
✓ Branch 1 taken 40 times.
6132 if(it->second.scriptname != "")
12798 {
12799 40 numgenericbindings++;
12800 40 }
12801 6132 }
12802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12803 {
12804 new_return(2043);
12805 }
12806
12807
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12808 {
12809
2/2
✓ Branch 0 taken 6092 times.
✓ Branch 1 taken 40 times.
6132 if(it->second.scriptname != "")
12810 {
12811
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_iputw(it->first,f))
12812 {
12813 new_return(2044);
12814 }
12815
12816
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12817 {
12818 new_return(2045);
12819 }
12820
12821
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12822 {
12823 new_return(2046);
12824 }
12825 40 }
12826 6132 }
12827
12828 //generic scripts
12829 12 word numsubscreenbindings=0;
12830
12831
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12832 {
12833
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12834 {
12835 numsubscreenbindings++;
12836 }
12837 3060 }
12838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12839 {
12840 new_return(2047);
12841 }
12842
12843
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12844 {
12845
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12846 {
12847 if(!p_iputw(it->first,f))
12848 {
12849 new_return(2048);
12850 }
12851
12852 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12853 {
12854 new_return(2049);
12855 }
12856
12857 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12858 {
12859 new_return(2050);
12860 }
12861 }
12862 3060 }
12863
12864
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12865 {
12866 6 section_size=writesize;
12867 6 }
12868 12 }
12869
12870
12871
12872
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12873 {
12874 char ebuf[80];
12875 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12876 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12877 }
12878
12879 6 new_return(0);
12880 //return 0; //this is just here to stomp the compiler from whining.
12881 //the irony is that it causes an "unreachable code" warning.
12882 9 }
12883
12884 12 int32_t write_quest_zasm(PACKFILE *f)
12885 {
12886 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12887
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12888 {
12889 if(!p_iputl(0,f))
12890 new_return(1);
12891
12892 return 0;
12893 }
12894
12895 12 auto& zasm = zasm_scripts[0]->zasm;
12896 12 size_t num_commands = zasm.size();
12897
12898
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12899 new_return(1);
12900
12901
2/2
✓ Branch 0 taken 345632 times.
✓ Branch 1 taken 12 times.
345644 for(int32_t j=0; j<num_commands; j++)
12902 {
12903 345632 auto& zas = zasm[j];
12904
12905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 345632 times.
345632 if(zas.command==0xFFFF)
12906 continue;
12907 else
12908 {
12909
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputw(zas.command,f))
12910 new_return(2);
12911
12912
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg1,f))
12913 new_return(3);
12914
12915
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg2,f))
12916 new_return(4);
12917
12918
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(zas.arg3,f))
12919 new_return(5);
12920
12921 345632 uint32_t sz = 0;
12922
2/2
✓ Branch 0 taken 344678 times.
✓ Branch 1 taken 954 times.
345632 if(zas.strptr)
12923 954 sz = zas.strptr->size();
12924
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(sz,f))
12925 new_return(6);
12926
2/2
✓ Branch 0 taken 344690 times.
✓ Branch 1 taken 942 times.
345632 if(sz)
12927 {
12928 942 auto& str = *zas.strptr;
12929
2/2
✓ Branch 0 taken 19592 times.
✓ Branch 1 taken 942 times.
20534 for(size_t q = 0; q < sz; ++q)
12930 {
12931
1/2
✓ Branch 0 taken 19592 times.
✗ Branch 1 not taken.
19592 if(!p_putc(str[q],f))
12932 new_return(7);
12933 19592 }
12934 942 }
12935 345632 sz = 0;
12936
2/2
✓ Branch 0 taken 345432 times.
✓ Branch 1 taken 200 times.
345632 if(zas.vecptr)
12937 200 sz = zas.vecptr->size();
12938
1/2
✓ Branch 0 taken 345632 times.
✗ Branch 1 not taken.
345632 if(!p_iputl(sz,f))
12939 new_return(8);
12940
2/2
✓ Branch 0 taken 345432 times.
✓ Branch 1 taken 200 times.
345632 if(sz) //vector found
12941 {
12942 200 auto& vec = *zas.vecptr;
12943
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 200 times.
1000 for(size_t q = 0; q < sz; ++q)
12944 {
12945
1/2
✓ Branch 0 taken 800 times.
✗ Branch 1 not taken.
800 if(!p_iputl(vec[q],f))
12946 new_return(9);
12947 800 }
12948 200 }
12949 }
12950 345632 }
12951 12 return 0;
12952 12 }
12953
12954 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
12955 {
12956
2/2
✓ Branch 0 taken 45988 times.
✓ Branch 1 taken 248 times.
46236 if (!script->valid())
12957 {
12958
1/2
✓ Branch 0 taken 45988 times.
✗ Branch 1 not taken.
45988 if (!p_putc(0, f))
12959 new_return(-1);
12960 45988 return 0;
12961 }
12962
12963
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if (!p_putc(1, f))
12964 new_return(-1);
12965
12966 248 zasm_meta const& tmeta = script->meta;
12967
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.zasm_v,f))
12968 new_return(1);
12969
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.meta_v,f))
12970 new_return(2);
12971
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.ffscript_v,f))
12972 new_return(3);
12973
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putc((int)tmeta.script_type,f))
12974 new_return(4);
12975
12976
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(int32_t q = 0; q < 8; ++q)
12977 {
12978
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.run_idens[q],f))
12979 new_return(5);
12980 1984 }
12981
12982
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(int32_t q = 0; q < 8; ++q)
12983
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putc(tmeta.run_types[q],f))
12984 new_return(6);
12985
12986
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putc(tmeta.flags,f))
12987 new_return(7);
12988
12989
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v1,f))
12990 new_return(8);
12991
12992
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v2,f))
12993 new_return(9);
12994
12995
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v3,f))
12996 new_return(10);
12997
12998
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputw(tmeta.compiler_v4,f))
12999 new_return(11);
13000
13001
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putcstr(tmeta.script_name,f))
13002 new_return(12);
13003
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_putcstr(tmeta.author,f))
13004 new_return(13);
13005
2/2
✓ Branch 0 taken 2480 times.
✓ Branch 1 taken 248 times.
2728 for(auto q = 0; q < 10; ++q)
13006 {
13007
1/2
✓ Branch 0 taken 2480 times.
✗ Branch 1 not taken.
2480 if(!p_putcstr(tmeta.attributes[q],f))
13008 new_return(14);
13009
1/2
✓ Branch 0 taken 2480 times.
✗ Branch 1 not taken.
2480 if(!p_putwstr(tmeta.attributes_help[q],f))
13010 new_return(15);
13011 2480 }
13012
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13013 {
13014
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.attribytes[q],f))
13015 new_return(16);
13016
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.attribytes_help[q],f))
13017 new_return(17);
13018 1984 }
13019
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13020 {
13021
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.attrishorts[q],f))
13022 new_return(18);
13023
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13024 new_return(19);
13025 1984 }
13026
2/2
✓ Branch 0 taken 3968 times.
✓ Branch 1 taken 248 times.
4216 for(auto q = 0; q < 16; ++q)
13027 {
13028
1/2
✓ Branch 0 taken 3968 times.
✗ Branch 1 not taken.
3968 if(!p_putcstr(tmeta.usrflags[q],f))
13029 new_return(20);
13030
1/2
✓ Branch 0 taken 3968 times.
✗ Branch 1 not taken.
3968 if(!p_putwstr(tmeta.usrflags_help[q],f))
13031 new_return(21);
13032 3968 }
13033
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13034 {
13035
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putcstr(tmeta.initd[q],f))
13036 new_return(22);
13037
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putwstr(tmeta.initd_help[q],f))
13038 new_return(23);
13039 1984 }
13040
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 248 times.
2232 for(auto q = 0; q < 8; ++q)
13041 {
13042
1/2
✓ Branch 0 taken 1984 times.
✗ Branch 1 not taken.
1984 if(!p_putc(tmeta.initd_type[q],f))
13043 new_return(24);
13044 1984 }
13045
13046
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 if(!p_iputl(script->pc, f))
13047 new_return(25);
13048
13049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 248 times.
248 if(!p_iputl(script->end_pc, f))
13050 new_return(26);
13051
13052 248 return 0;
13053 46236 }
13054
13055
13056 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13057 {
13058 3 dword section_id = ID_FFSCRIPT;
13059 3 dword section_version = 26;
13060 3 dword section_cversion = 1;
13061 3 dword section_size = 0;
13062 3 dword zasmmeta_version = 5;
13063 3 byte numscripts = 0;
13064 3 numscripts = numscripts; //to avoid unused variables warnings
13065
13066 //section id
13067
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13068 {
13069 new_return(1);
13070 }
13071
13072 //section version info
13073
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13074 {
13075 new_return(2);
13076 }
13077
13078
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13079 {
13080 new_return(3);
13081 }
13082
13083
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13084 {
13085 new_return(4);
13086 }
13087
13088
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13089 {
13090 6 fake_pack_writing=(writecycle==0);
13091
13092 //section size
13093
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13094 {
13095 new_return(5);
13096 }
13097
13098 6 writesize=0;
13099
13100
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13101 {
13102 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13103 3072 fake_pack_writing=(writecycle==0);
13104
13105
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13106 {
13107 new_return(ret);
13108 }
13109 3072 }
13110
13111
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13112 {
13113 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13114 1536 fake_pack_writing=(writecycle==0);
13115
13116
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13117 {
13118 new_return(ret);
13119 }
13120 1536 }
13121
13122
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13123 {
13124 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13125 1536 fake_pack_writing=(writecycle==0);
13126
13127
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13128 {
13129 new_return(ret);
13130 }
13131 1536 }
13132
13133
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13134
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13135 {
13136 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13137 1536 fake_pack_writing=(writecycle==0);
13138
13139
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13140 {
13141 new_return(ret);
13142 }
13143 1536 }
13144
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13145
13146
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13147 {
13148 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13149 1536 fake_pack_writing=(writecycle==0);
13150
13151
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13152 {
13153 new_return(ret);
13154 }
13155 1536 }
13156
13157
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13158 {
13159 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13160 48 fake_pack_writing=(writecycle==0);
13161
13162
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13163 {
13164 new_return(ret);
13165 }
13166 48 }
13167
13168
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13169 {
13170 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13171 30 fake_pack_writing=(writecycle==0);
13172
13173
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13174 {
13175 new_return(ret);
13176 }
13177 30 }
13178
13179
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13180 {
13181 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13182 1536 fake_pack_writing=(writecycle==0);
13183
13184
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13185 {
13186 new_return(ret);
13187 }
13188 1536 }
13189
13190
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13191 {
13192 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13193 1536 fake_pack_writing=(writecycle==0);
13194
13195
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13196 {
13197 new_return(ret);
13198 }
13199 1536 }
13200
13201
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13202 {
13203 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13204 1536 fake_pack_writing=(writecycle==0);
13205
13206
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13207 {
13208 new_return(ret);
13209 }
13210 1536 }
13211
13212
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13213 {
13214 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13215 1536 fake_pack_writing=(writecycle==0);
13216
13217
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13218 {
13219 new_return(ret);
13220 }
13221 1536 }
13222
13223
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13224 {
13225 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13226 3072 fake_pack_writing=(writecycle==0);
13227
13228
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13229 {
13230 new_return(ret);
13231 }
13232 3072 }
13233
13234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13235 {
13236 new_return(2000);
13237 }
13238
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13239 {
13240 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13241 3072 fake_pack_writing=(writecycle==0);
13242
13243
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13244 {
13245 new_return(ret);
13246 }
13247 3072 }
13248
13249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13250 {
13251 new_return(2001);
13252 }
13253
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13254 {
13255 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13256 1536 fake_pack_writing=(writecycle==0);
13257
13258
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13259 {
13260 new_return(ret);
13261 }
13262 1536 }
13263
13264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13265 {
13266 new_return(2001);
13267 }
13268
13269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13270 {
13271 new_return(2002);
13272 }
13273
13274 6 word numffcbindings=0;
13275
13276
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13277 {
13278
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13279 {
13280 206 numffcbindings++;
13281 206 }
13282 3066 }
13283
13284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13285 {
13286 new_return(2003);
13287 }
13288
13289
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13290 {
13291
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13292 {
13293
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13294 {
13295 new_return(2004);
13296 }
13297
13298
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13299 {
13300 new_return(2005);
13301 }
13302
13303
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13304 {
13305 new_return(2006);
13306 }
13307 206 }
13308 3066 }
13309
13310 6 word numglobalbindings=0;
13311
13312
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13313 {
13314
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13315 {
13316 18 numglobalbindings++;
13317 18 }
13318 48 }
13319
13320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13321 {
13322 new_return(2007);
13323 }
13324
13325
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13326 {
13327
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13328 {
13329
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13330 {
13331 new_return(2008);
13332 }
13333
13334
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13335 {
13336 new_return(2009);
13337 }
13338
13339
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13340 {
13341 new_return(2010);
13342 }
13343 18 }
13344 48 }
13345
13346 6 word numitembindings=0;
13347
13348
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13349 {
13350
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13351 {
13352 18 numitembindings++;
13353 18 }
13354 1530 }
13355
13356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13357 {
13358 new_return(2011);
13359 }
13360
13361
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13362 {
13363
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13364 {
13365
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13366 {
13367 new_return(2012);
13368 }
13369
13370
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13371 {
13372 new_return(2013);
13373 }
13374
13375
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13376 {
13377 new_return(2014);
13378 }
13379 18 }
13380 1530 }
13381
13382 //new script types
13383 //npc scripts
13384 6 word numnpcbindings=0;
13385
13386
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13387 {
13388
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13389 {
13390 numnpcbindings++;
13391 }
13392 1530 }
13393
13394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13395 {
13396 new_return(2015);
13397 }
13398
13399
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13400 {
13401
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13402 {
13403 if(!p_iputw(it->first,f))
13404 {
13405 new_return(2016);
13406 }
13407
13408 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13409 {
13410 new_return(2017);
13411 }
13412
13413 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13414 {
13415 new_return(2018);
13416 }
13417 }
13418 1530 }
13419
13420 //lweapon
13421
13422 6 word numlwpnbindings=0;
13423
13424
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13425 {
13426
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13427 {
13428 numlwpnbindings++;
13429 }
13430 1530 }
13431
13432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13433 {
13434 new_return(2019);
13435 }
13436
13437
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13438 {
13439
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13440 {
13441 if(!p_iputw(it->first,f))
13442 {
13443 new_return(2020);
13444 }
13445
13446 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13447 {
13448 new_return(2021);
13449 }
13450
13451 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13452 {
13453 new_return(2022);
13454 }
13455 }
13456 1530 }
13457
13458 //////
13459
13460 //eweapon
13461
13462
13463 6 word numewpnbindings=0;
13464
13465
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13466 {
13467
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13468 {
13469 numewpnbindings++;
13470 }
13471 1530 }
13472
13473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13474 {
13475 new_return(2023);
13476 }
13477
13478
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13479 {
13480
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13481 {
13482 if(!p_iputw(it->first,f))
13483 {
13484 new_return(2024);
13485 }
13486
13487 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13488 {
13489 new_return(2025);
13490 }
13491
13492 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13493 {
13494 new_return(2026);
13495 }
13496 }
13497 1530 }
13498
13499 //player scripts
13500 6 word numherobindings=0;
13501
13502
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13503 {
13504
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13505 {
13506 2 numherobindings++;
13507 2 }
13508 24 }
13509
13510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13511 {
13512 new_return(2027);
13513 }
13514
13515
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13516 {
13517
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13518 {
13519
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13520 {
13521 new_return(2028);
13522 }
13523
13524
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13525 {
13526 new_return(2029);
13527 }
13528
13529
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13530 {
13531 new_return(2030);
13532 }
13533 2 }
13534 24 }
13535
13536 //dmap scripts
13537 6 word numdmapbindings=0;
13538
13539
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13540 {
13541
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13542 {
13543 numdmapbindings++;
13544 }
13545 1530 }
13546
13547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13548 {
13549 new_return(2031);
13550 }
13551
13552
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13553 {
13554
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13555 {
13556 if(!p_iputw(it->first,f))
13557 {
13558 new_return(2032);
13559 }
13560
13561 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13562 {
13563 new_return(2033);
13564 }
13565
13566 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13567 {
13568 new_return(2034);
13569 }
13570 }
13571 1530 }
13572
13573 //screen scripts
13574 6 word numscreenbindings=0;
13575
13576
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13577 {
13578
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13579 {
13580 14 numscreenbindings++;
13581 14 }
13582 1530 }
13583
13584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13585 {
13586 new_return(2035);
13587 }
13588
13589
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13590 {
13591
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13592 {
13593
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13594 {
13595 new_return(2036);
13596 }
13597
13598
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13599 {
13600 new_return(2037);
13601 }
13602
13603
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13604 {
13605 new_return(2038);
13606 }
13607 14 }
13608 1530 }
13609 //item sprite scripts
13610 6 word numitemspritebindings=0;
13611
13612
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13613 {
13614
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13615 {
13616 numitemspritebindings++;
13617 }
13618 1530 }
13619
13620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13621 {
13622 new_return(2039);
13623 }
13624
13625
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13626 {
13627
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13628 {
13629 if(!p_iputw(it->first,f))
13630 {
13631 new_return(2040);
13632 }
13633
13634 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13635 {
13636 new_return(2041);
13637 }
13638
13639 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13640 {
13641 new_return(2042);
13642 }
13643 }
13644 1530 }
13645
13646 //combo scripts
13647 6 word numcombobindings=0;
13648
13649
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13650 {
13651
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13652 {
13653 numcombobindings++;
13654 }
13655 3066 }
13656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13657 {
13658 new_return(2043);
13659 }
13660
13661
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13662 {
13663
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13664 {
13665 if(!p_iputw(it->first,f))
13666 {
13667 new_return(2044);
13668 }
13669
13670 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13671 {
13672 new_return(2045);
13673 }
13674
13675 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13676 {
13677 new_return(2046);
13678 }
13679 }
13680 3066 }
13681 //subscreen scripts
13682 6 word numgenericbindings=0;
13683
13684
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13685 {
13686
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13687 {
13688 numgenericbindings++;
13689 }
13690 3066 }
13691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13692 {
13693 new_return(2043);
13694 }
13695
13696
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13697 {
13698
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13699 {
13700 if(!p_iputw(it->first,f))
13701 {
13702 new_return(2044);
13703 }
13704
13705 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13706 {
13707 new_return(2045);
13708 }
13709
13710 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13711 {
13712 new_return(2046);
13713 }
13714 }
13715 3066 }
13716
13717 //generic scripts
13718 6 word numsubscreenbindings=0;
13719
13720
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13721 {
13722
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13723 {
13724 numsubscreenbindings++;
13725 }
13726 1530 }
13727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13728 {
13729 new_return(2047);
13730 }
13731
13732
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13733 {
13734
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13735 {
13736 if(!p_iputw(it->first,f))
13737 {
13738 new_return(2048);
13739 }
13740
13741 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13742 {
13743 new_return(2049);
13744 }
13745
13746 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13747 {
13748 new_return(2050);
13749 }
13750 }
13751 1530 }
13752
13753
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13754 {
13755 3 section_size=writesize;
13756 3 }
13757 6 }
13758
13759
13760
13761
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13762 {
13763 char ebuf[80];
13764 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13765 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13766 }
13767
13768 3 new_return(0);
13769 //return 0; //this is just here to stomp the compiler from whining.
13770 //the irony is that it causes an "unreachable code" warning.
13771 3 }
13772
13773 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13774 {
13775 //these are here to bypass compiler warnings about unused arguments
13776 23118 Header=Header;
13777 23118 i=i;
13778
13779
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13780
13781
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13782 {
13783 new_return(6);
13784 }
13785
13786 //Metadata
13787 23118 zasm_meta const& tmeta = script->meta;
13788
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13789 {
13790 new_return(7);
13791 }
13792
13793
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13794 {
13795 new_return(8);
13796 }
13797
13798
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13799 {
13800 new_return(9);
13801 }
13802
13803
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13804 {
13805 new_return(10);
13806 }
13807
13808
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13809 {
13810
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13811 new_return(11);
13812 184944 }
13813
13814
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13815 {
13816
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13817 {
13818 new_return(12);
13819 }
13820 184944 }
13821
13822
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13823 {
13824 new_return(13);
13825 }
13826
13827
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13828 {
13829 new_return(14);
13830 }
13831
13832
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13833 {
13834 new_return(15);
13835 }
13836
13837
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13838 {
13839 new_return(16);
13840 }
13841
13842
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13843 {
13844 new_return(17);
13845 }
13846
13847
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13848 new_return(18);
13849
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13850 new_return(19);
13851
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13852 {
13853
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13854 new_return(27);
13855
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13856 new_return(28);
13857 231180 }
13858
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13859 {
13860
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13861 new_return(29);
13862
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13863 new_return(30);
13864 184944 }
13865
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13866 {
13867
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13868 new_return(31);
13869
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13870 new_return(32);
13871 184944 }
13872
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13873 {
13874
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13875 new_return(33);
13876
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13877 new_return(34);
13878 369888 }
13879
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13880 {
13881
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13882 new_return(35);
13883
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13884 new_return(36);
13885 184944 }
13886
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13887 {
13888
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13889 new_return(37);
13890 184944 }
13891
13892
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13893 {
13894 2056888 auto& zas = script->zasm_script->zasm[j];
13895
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13896 {
13897 new_return(20);
13898 }
13899
13900
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13901 {
13902 11830 break;
13903 }
13904 else
13905 {
13906
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13907 {
13908 new_return(21);
13909 }
13910
13911
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13912 {
13913 new_return(22);
13914 }
13915
13916
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13917 {
13918 new_return(23);
13919 }
13920
13921 2045058 uint32_t sz = 0;
13922
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13923 2340 sz = zas.strptr->size();
13924
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13925 {
13926 new_return(23);
13927 }
13928
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13929 {
13930 2340 auto& str = *zas.strptr;
13931
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13932 {
13933
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13934 {
13935 new_return(24);
13936 }
13937 214720 }
13938 2340 }
13939 2045058 sz = 0;
13940
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13941 22 sz = zas.vecptr->size();
13942
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13943 {
13944 new_return(25);
13945 }
13946
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13947 {
13948 22 auto& vec = *zas.vecptr;
13949
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13950 {
13951
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13952 {
13953 new_return(26);
13954 }
13955 352 }
13956 22 }
13957 }
13958 2045058 }
13959
13960 23118 new_return(0);
13961 }
13962
13963 extern SAMPLE customsfxdata[WAV_COUNT];
13964 extern uint8_t customsfxflag[WAV_COUNT>>3];
13965
13966 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13967 {
13968 //these are here to bypass compiler warnings about unused arguments
13969 9 Header=Header;
13970
13971 9 dword section_id=ID_SFX;
13972 9 dword section_version=V_SFX;
13973 9 dword section_size=0;
13974
13975 //section id
13976
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
13977 {
13978 new_return(1);
13979 }
13980
13981 //section version info
13982
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
13983 {
13984 new_return(2);
13985 }
13986
13987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
13988 {
13989 new_return(3);
13990 }
13991
13992
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13993 {
13994 18 fake_pack_writing=(writecycle==0);
13995
13996 //section size
13997
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
13998 {
13999 new_return(4);
14000 }
14001
14002 18 writesize=0;
14003
14004
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14005 {
14006
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14007 {
14008 new_return(5);
14009 }
14010 576 }
14011
14012
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14013 {
14014
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14015 3330 continue;
14016
14017
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14018 {
14019 new_return(5);
14020 }
14021 1260 }
14022
14023
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14024 {
14025
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14026 3330 continue;
14027
14028
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14029 {
14030 new_return(5);
14031 }
14032
14033
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14034 {
14035 new_return(6);
14036 }
14037
14038
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14039 {
14040 new_return(7);
14041 }
14042
14043
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14044 {
14045 new_return(8);
14046 }
14047
14048
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14049 {
14050 new_return(9);
14051 }
14052
14053
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14054 {
14055 new_return(10);
14056 }
14057
14058
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14059 {
14060 new_return(11);
14061 }
14062
14063
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14064 {
14065 new_return(12);
14066 }
14067
14068 //de-endianfy the data
14069 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14070
14071
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14072 {
14073
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14074 {
14075 new_return(13);
14076 }
14077 28596352 }
14078 1260 }
14079
14080
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14081 {
14082 9 section_size=writesize;
14083 9 }
14084 18 }
14085
14086
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14087 {
14088 char ebuf[80];
14089 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14090 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14091 }
14092
14093 9 new_return(0);
14094 }
14095
14096 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14097 {
14098 9 dword section_id=ID_INITDATA;
14099 9 dword section_version=V_INITDATA;
14100 9 dword section_size = 0;
14101
14102 9 zinit.last_map=Map.getCurrMap();
14103 9 zinit.last_screen=Map.getCurrScr();
14104 9 zinit.normalize();
14105
14106 //section id
14107
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14108 {
14109 new_return(1);
14110 }
14111
14112 //section version info
14113
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14114 {
14115 new_return(2);
14116 }
14117
14118
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14119 {
14120 new_return(3);
14121 }
14122
14123 //TODO
14124
14125
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14126 {
14127 18 fake_pack_writing=(writecycle==0);
14128
14129 //section size
14130
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14131 new_return(4);
14132
14133 18 writesize=0;
14134
14135
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14136
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14137 new_return(5);
14138
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14139 {
14140
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14141 new_return(6);
14142 9216 }
14143
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14144 new_return(10);
14145
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14146 new_return(11);
14147
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14148
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14149 new_return(12);
14150
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14151
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14152 new_return(13);
14153
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14154 new_return(14);
14155
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14156 new_return(15);
14157
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14158 new_return(16);
14159
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14160 new_return(17);
14161
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14162 new_return(18);
14163
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14164 new_return(19);
14165
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14166 new_return(20);
14167
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14168 new_return(21);
14169
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14170 new_return(22);
14171
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14172 new_return(23);
14173
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14174 new_return(24);
14175
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14176 new_return(25);
14177
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14178 new_return(26);
14179
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14180 new_return(27);
14181
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14182 new_return(28);
14183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14184 new_return(29);
14185
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14186 new_return(30);
14187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14188 new_return(31);
14189
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14190 new_return(32);
14191
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14192 new_return(33);
14193
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14194 new_return(34);
14195
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14196 new_return(35);
14197
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14198 new_return(36);
14199
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14200 new_return(37);
14201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14202 new_return(38);
14203
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14204 new_return(39);
14205
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14206 new_return(40);
14207
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14208 new_return(41);
14209
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14210 new_return(42);
14211
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14212 new_return(43);
14213
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14214 new_return(44);
14215
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14216 new_return(45);
14217
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14218 new_return(46);
14219
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14220 new_return(47);
14221
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14222 new_return(48);
14223
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14224 new_return(49);
14225
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14226 new_return(50);
14227
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14228 new_return(51);
14229
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14230 new_return(52);
14231
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14232 new_return(53);
14233
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14234 new_return(54);
14235
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14236 new_return(55);
14237
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14238 new_return(56);
14239
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14240 new_return(57);
14241
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14242 new_return(58);
14243
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14244 new_return(59);
14245
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14246 new_return(60);
14247
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14248 new_return(61);
14249
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14250 new_return(62);
14251
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14252 new_return(63);
14253
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14254 new_return(64);
14255
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14256 new_return(65);
14257
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14258 new_return(66);
14259
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14260 new_return(67);
14261
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14262 new_return(68);
14263
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14264 new_return(69);
14265
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14266 new_return(70);
14267
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14268 new_return(71);
14269
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14270 new_return(72);
14271
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14272 new_return(73);
14273
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14274 new_return(74);
14275
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14276 new_return(75);
14277
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14278
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14279 new_return(76);
14280
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14281 new_return(77);
14282
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14283 new_return(78);
14284
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14285 new_return(79);
14286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14287 new_return(80);
14288
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14289 new_return(81);
14290
14291
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14292 {
14293 9 section_size=writesize;
14294 9 }
14295 18 }
14296
14297
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14298 {
14299 char ebuf[80];
14300 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14301 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14302 }
14303
14304 9 new_return(0);
14305 }
14306
14307 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14308 {
14309 //these are here to bypass compiler warnings about unused arguments
14310 9 Header=Header;
14311
14312 9 dword section_id=ID_ITEMDROPSETS;
14313 9 dword section_version=V_ITEMDROPSETS;
14314 // dword section_size=0;
14315 9 dword section_size = 0;
14316 9 word num_item_drop_sets=count_item_drop_sets();
14317
14318 //section id
14319
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14320 {
14321 new_return(1);
14322 }
14323
14324 //section version info
14325
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14326 {
14327 new_return(2);
14328 }
14329
14330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14331 {
14332 new_return(3);
14333 }
14334
14335
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14336 {
14337 18 fake_pack_writing=(writecycle==0);
14338
14339 //section size
14340
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14341 {
14342 new_return(4);
14343 }
14344
14345 18 writesize=0;
14346
14347 //finally... section data
14348
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14349 {
14350 new_return(5);
14351 }
14352
14353
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14354 {
14355
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14356 {
14357 new_return(6);
14358 }
14359
14360
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14361 {
14362
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14363 {
14364 new_return(7);
14365 }
14366 2360 }
14367
14368
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14369 {
14370
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14371 {
14372 new_return(8);
14373 }
14374 2596 }
14375 236 }
14376
14377
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14378 {
14379 9 section_size=writesize;
14380 9 }
14381 18 }
14382
14383
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14384 {
14385 char ebuf[80];
14386 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14387 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14388 }
14389
14390 9 new_return(0);
14391 }
14392
14393 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14394 {
14395 9 dword section_id=ID_FAVORITES;
14396 9 dword section_version=V_FAVORITES;
14397 9 dword section_size = 0;
14398
14399 //section id
14400
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14401 {
14402 new_return(1);
14403 }
14404
14405 //section version info
14406
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14407 {
14408 new_return(2);
14409 }
14410
14411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14412 {
14413 new_return(3);
14414 }
14415
14416
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14417 {
14418 18 fake_pack_writing=(writecycle==0);
14419
14420 //section size
14421
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14422 new_return(4);
14423
14424 18 writesize=0;
14425
14426
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14427 new_return(16);
14428
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14429 new_return(17);
14430
14431 18 word favcmb_cnt = 0;
14432
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14433
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14434 {
14435 14 favcmb_cnt = q+1;
14436 14 break;
14437 }
14438
14439
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14440 new_return(5);
14441
14442
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14443 {
14444
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14445 new_return(6);
14446
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14447 new_return(7);
14448 460 }
14449
14450
14451 18 word max_combo_cols = MAX_COMBO_COLS;
14452
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14453 new_return(9);
14454
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14455 {
14456
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14457 new_return(10);
14458
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14459 new_return(11);
14460
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14461 new_return(12);
14462 72 }
14463 18 word max_mappages = MAX_MAPPAGE_BTNS;
14464
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14465 new_return(13);
14466
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14467 {
14468
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14469 new_return(14);
14470
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14471 new_return(15);
14472 162 }
14473
14474
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14475 {
14476 9 section_size=writesize;
14477 9 }
14478 18 }
14479
14480
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14481 {
14482 char ebuf[80];
14483 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14484 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14485 }
14486
14487 9 new_return(0);
14488 }
14489
14490 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14491 {
14492
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14493 9 reset_combo_animations();
14494 9 reset_combo_animations2();
14495 9 strcpy(header.id_str,QH_NEWIDSTR);
14496 9 header.zelda_version = ZELDA_VERSION;
14497 9 header.internal = INTERNAL_VERSION;
14498 9 header.data_flags[ZQ_TILES] = true;
14499 9 header.data_flags[ZQ_CHEATS2] = 1;
14500 9 header.build=VERSION_BUILD;
14501
14502
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14503 {
14504 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14505 2268 }
14506
14507 char zinfofilename[2048];
14508 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14509
14510 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14511 9 box_out("Saving Quest...");
14512 9 box_eol();
14513 9 box_eol();
14514
14515
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14516
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14517
14518
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14519 return 1;
14520
14521
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14522
14523
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14524 return 2;
14525
14526
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14527
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14528
14529
14530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14531 {
14532 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14533
14534 box_out("Writing ZInfo...");
14535 if(inf)
14536 {
14537 if(writezinfo(inf,ZI)!=0)
14538 return 2;
14539
14540 pack_fclose(inf);
14541 box_out("okay.");
14542 }
14543 else box_out(" ...file failure");
14544 box_eol();
14545 }
14546 else
14547 {
14548
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14549
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14550 return 2;
14551
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14552
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14553 }
14554
14555
14556
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14557
14558
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14559 return 3;
14560
14561
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14562
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14563
14564
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14565
14566
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14567 return 4;
14568
14569
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14570
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14571
14572
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14573
14574
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14575 return 5;
14576
14577
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14578
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14579
14580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14581
14582
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14583 return 6;
14584
14585
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14586
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14587
14588
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14589
14590
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14591 return 7;
14592
14593
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14594
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14595
14596
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14597
14598
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14599 return 8;
14600
14601
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14602
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14603
14604
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14605
14606
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14607 return 9;
14608
14609
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14610
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14611
14612
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14613
14614
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14615 return 10;
14616
14617
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14618
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14619
14620
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14621
14622
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14623 return 11;
14624
14625
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14626
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14627
14628
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14629
14630
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14631 return 12;
14632
14633
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14634
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14635
14636
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14637
14638
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14639 return 13;
14640
14641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14642
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14643
14644
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14645
14646
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14647 return 14;
14648
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14650
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14651
14652
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14653
14654
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14655 return 15;
14656
14657
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14658
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14659
14660
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14661
14662
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14663 return 16;
14664
14665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14667
14668
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14669
14670
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14671 return 17;
14672
14673
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14674
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14675
14676
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14677
14678
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14679 return 18;
14680
14681
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14682
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14683
14684
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14685
14686
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14687 return 19;
14688
14689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14691
14692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14693
14694
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14695 return 20;
14696
14697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14698
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14699
14700
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14701
14702
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14703 return 21;
14704
14705
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14706
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14707
14708
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14709
14710
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14711 return 22;
14712
14713
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14714
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14715
14716
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14717
14718
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14719 return 23;
14720
14721
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14722
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14723
14724
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14725
14726
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14727 return 24;
14728
14729
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14730
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14731
14732
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14733
14734
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14735 return 25;
14736
14737
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14738
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14739
14740
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14741
14742
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14743 return 26;
14744
14745
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14746
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14747
14748
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14749
14750
14751
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14752 {
14753 char const* kfname = filename;
14754 char keyfilename[2048]={0};
14755 zprint2("Writing key files for '%s'\n", kfname);
14756
14757 char temp_pw[QSTPWD_LEN] = {0};
14758 uint ind = 0;
14759 for(char const* ext : {"key","zpwd","zcheat"})
14760 {
14761 replace_extension(keyfilename, kfname, ext, 2047);
14762 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14763 char msg[80] = {0};
14764 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14765 msg[78]=13;
14766 msg[79]=10;
14767 pfwrite(msg, 80, fp);
14768 p_iputw(header.zelda_version,fp);
14769 p_putc(header.build,fp);
14770 char const* pwd = header.password;
14771 if(ind == 2) //.zcheat, hashed pwd
14772 {
14773 char hashmap = 'Z';
14774 hashmap += 'Q';
14775 hashmap += 'U';
14776 hashmap += 'E';
14777 hashmap += 'S';
14778 hashmap += 'T';
14779 for ( int q = 0; q < QSTPWD_LEN; ++q )
14780 {
14781 temp_pw[q] = header.password[q];
14782 temp_pw[q] += hashmap;
14783 }
14784 pwd = temp_pw;
14785 }
14786 pfwrite(pwd, strlen(pwd), fp);
14787 pack_fclose(fp);
14788 ++ind;
14789 }
14790 }
14791
14792 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14793 9 std::error_code ec;
14794
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14796 {
14797 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14798 return ec.value();
14799 }
14800
14801
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14802
14803 #ifdef __EMSCRIPTEN__
14804 em_sync_fs();
14805 #endif
14806
14807 9 return 0;
14808 9 }
14809
14810 // #ifdef _WIN32
14811 // static std::time_t to_time_t(FILETIME const& ft) {
14812 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14813 // t -= 116444736000000000ull;
14814 // t /= 10000000u;
14815 // return static_cast<std::time_t>(t);
14816 // }
14817 // #else
14818 // #endif
14819 template<typename TP>
14820 6 static std::time_t to_time_t(TP tp) {
14821 using namespace std::chrono;
14822 6 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14823 6 return system_clock::to_time_t(sctp);
14824 }
14825
14826 6 std::string get_time_last_modified_string(std::string path)
14827 {
14828
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto write_time = fs::last_write_time(path);
14829 // TODO: C++20 but not supported yet.
14830 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14831 6 std::time_t tt = to_time_t(write_time);
14832 6 std::tm *gmt = std::gmtime(&tt);
14833 6 std::stringstream buffer;
14834
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 buffer << std::put_time(gmt, "%Y-%m-%d");
14835
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string formattedFileTime = buffer.str();
14836 6 return formattedFileTime;
14837
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 }
14838
14839 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14840 {
14841 // Always backup quest if it was last saved in a different version of the editor,
14842 // or if this a new file and is overwritting another qst file.
14843
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14844 {
14845 6 std::string backup_name;
14846
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string last_mod = get_time_last_modified_string(filename);
14847
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (strlen(header.zelda_version_string) > 0)
14848 {
14849
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14850 6 }
14851 else
14852 {
14853 backup_name = fmt::format("{}", last_mod);
14854 }
14855
7/14
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
6 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14856
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 fs::path backup_path = fs::path("backups") / backup_fname;
14857
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!fs::exists(backup_path))
14858 {
14859
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::create_directories(fs::path("backups"));
14860
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 if (fs::copy_file(filename, backup_path))
14861 {
14862
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
6 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14863 6 }
14864 else
14865 {
14866 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14867 }
14868 6 }
14869 6 }
14870
14871 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14872 9 fake_pack_writing = false;
14873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14874 {
14875 box_out("-- Error saving quest file! --");
14876 box_end(true);
14877 }
14878 9 else box_end(false);
14879 9 return ret;
14880 }
14881
14882 9 int32_t save_quest(const char *filename, bool timed_save)
14883 {
14884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14885
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14886 char ext1[5];
14887 9 ext1[0]=0;
14888
14889
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14890 {
14891 sprintf(ext1, "qt");
14892 }
14893 else
14894 {
14895 9 sprintf(ext1, "qb");
14896 }
14897
14898
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14899 {
14900 char backupname[2048];
14901 char backupname2[2048];
14902 char ext[12];
14903
14904 for(int32_t i=retention-1; i>0; --i)
14905 {
14906 sprintf(ext, "%s%d", ext1, i-1);
14907 replace_extension(backupname, filepath, ext, 2047);
14908
14909 if(exists(backupname))
14910 {
14911 sprintf(ext, "%s%d", ext1, i);
14912 replace_extension(backupname2, filepath, ext, 2047);
14913
14914 if(exists(backupname2))
14915 {
14916 remove(backupname2);
14917 }
14918
14919 rename(backupname, backupname2);
14920 }
14921 }
14922
14923 //don't do this if we're not saving to the same name -DD
14924 if(!timed_save && !strcmp(filepath, filename))
14925 {
14926 sprintf(ext, "%s%d", ext1, 0);
14927 replace_extension(backupname, filepath, ext, 2047);
14928 rename(filepath, backupname);
14929 }
14930 }
14931
14932 int32_t ret;
14933 9 ret = save_unencoded_quest(filename, compress, filename);
14934
14935 9 return ret;
14936 }
14937
14938 8 void center_zq_class_dialogs()
14939 {
14940 8 jwin_center_dialog(pwd_dlg);
14941 8 }
14942
14943 void zmap::prv_secrets(bool high16only)
14944 {
14945 mapscr *s = &prvscr;
14946 mapscr *t = prvlayers;
14947 int32_t ft=0;
14948
14949 for(int32_t i=0; i<176; i++)
14950 {
14951 if(!high16only)
14952 {
14953 for(int32_t j=-1; j<6; j++)
14954 {
14955 int32_t newflag = -1;
14956
14957 for(int32_t iter=0; iter<2; ++iter)
14958 {
14959 if(!t[j].valid)
14960 continue;
14961
14962 int32_t checkflag=combobuf[t[j].data[i]].flag;
14963
14964 if(iter==1)
14965 {
14966 checkflag=t[j].sflag[i];
14967 }
14968
14969 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
14970 if (ft != -1)
14971 {
14972 if(j==-1)
14973 {
14974 s->data[i] = s->secretcombo[ft];
14975 s->cset[i] = s->secretcset[ft];
14976 newflag = s->secretflag[ft];
14977 }
14978 else
14979 {
14980 t[j].data[i] = t[j].secretcombo[ft];
14981 t[j].cset[i] = t[j].secretcset[ft];
14982 newflag = t[j].secretflag[ft];
14983 }
14984 }
14985 }
14986
14987 if(newflag >-1)
14988 {
14989 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14990 }
14991 }
14992 }
14993
14994 //if(true)
14995 //{
14996 int32_t newflag = -1;
14997
14998 for(int32_t iter=0; iter<2; ++iter)
14999 {
15000 int32_t checkflag=combobuf[s->data[i]].flag;
15001
15002 if(iter==1)
15003 {
15004 checkflag=s->sflag[i];
15005 }
15006
15007 if((checkflag > 15)&&(checkflag < 32))
15008 {
15009 s->data[i] = s->secretcombo[(checkflag)-16+4];
15010 s->cset[i] = s->secretcset[(checkflag)-16+4];
15011 newflag = s->secretflag[(checkflag)-16+4];
15012 // putit = true;
15013 }
15014 }
15015
15016 if(newflag >-1) s->sflag[i] = newflag;
15017
15018 for(int32_t j=0; j<6; j++)
15019 {
15020 if(!t[j].valid) continue;
15021
15022 int32_t newflag2 = -1;
15023
15024 for(int32_t iter=0; iter<2; ++iter)
15025 {
15026 int32_t checkflag=combobuf[t[j].data[i]].flag;
15027
15028 if(iter==1)
15029 {
15030 checkflag=t[j].sflag[i];
15031 }
15032
15033 if((checkflag > 15)&&(checkflag < 32))
15034 {
15035 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15036 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15037 newflag2 = t[j].secretflag[(checkflag)-16+4];
15038 }
15039 }
15040
15041 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15042 }
15043 }
15044
15045 //FFCs
15046 word num_ffcs = s->numFFC();
15047 for(word i=0; i<num_ffcs; ++i)
15048 {
15049 if(!high16only)
15050 {
15051 for(int32_t iter=0; iter<1; ++iter)
15052 {
15053 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15054
15055 if(iter==1)
15056 {
15057 checkflag=s->sflag[i];
15058 }
15059
15060 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15061 if (ft != -1)
15062 {
15063 s->ffcs[i].data = s->secretcombo[ft];
15064 s->ffcs[i].cset = s->secretcset[ft];
15065 }
15066 }
15067 }
15068
15069 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15070 {
15071 for(int32_t iter=0; iter<1; ++iter)
15072 {
15073 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15074
15075 if(iter==1)
15076 {
15077 // FFCs can't have flags! Yet...
15078 }
15079
15080 if((checkflag > 15)&&(checkflag < 32))
15081 {
15082 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15083 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15084 }
15085 }
15086 }
15087 }
15088 }
15089